package com.pureut.storage.service.impl;


import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pureut.common.core.exception.GlobalException;
import com.pureut.common.core.utils.bean.BeanUtils;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.security.utils.DictUtils;
import com.pureut.production.api.FeignProductionService;
import com.pureut.storage.domain.OutboundLog;
import com.pureut.storage.domain.PublicGoods;
import com.pureut.storage.domain.WmsStockInfo;
import com.pureut.storage.domain.production.domain.DegreasOutputDetail;
import com.pureut.storage.domain.production.dto.ClothInspectionDetailDto;
import com.pureut.storage.domain.production.dto.FeedRecordDetailsDto;
import com.pureut.storage.domain.production.dto.RollPackingHistoryDto;
import com.pureut.storage.domain.production.dto.WmsSmallRollFoundationDto;
import com.pureut.storage.dto.*;
import com.pureut.storage.mapper.*;
import com.pureut.storage.service.WmsStockInfoService;
import com.pureut.storage.util.DateUtilss;
import com.pureut.storage.util.MessageRemindMqUtil;
import com.pureut.storage.utils.DocumentTypeEnum;
import com.pureut.storage.vo.*;
import com.pureut.system.api.FeignService;
import com.pureut.system.api.domain.SysDictData;
import com.pureut.system.api.domain.SysTheAlarmDto;
import com.pureut.system.api.domain.SysWorkbenchMessage;
import com.pureut.system.api.vo.QualityFreezeVo;
import com.pureut.system.api.vo.SysWorkbenchMessageVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.stream.Collectors;

import static com.pureut.common.core.utils.PageUtils.startPage;

/**
 * @author: CM
 * @date: 2023/1/6  13:50
 */
@Service
public class WmsStockInfoServiceImpl extends ServiceImpl<WmsStockInfoMapper, WmsStockInfo> implements WmsStockInfoService {

    /**
     * 库存mapper
     */
    @Resource
    WmsStockInfoMapper wmsStockInfoMapper;

    /**
     * 远程调用
     */
    @Resource
    private FeignService feignService;

    /**
     * 仓库
     */
    @Resource
    private WarehouseMapper warehouseMapper;

    /**
     * 生产
     */
    @Resource
    private FeignProductionService feignProductionService;

    /**
     * 生产领料
     */
    @Resource
    private StockOutInfoDetailMapper stockOutInfoDetailMapper;

    /**
     * 销售发货
     */
    @Resource
    private PickingSaleDetailMapper pickingSaleDetailMapper;

    /**
     * 返工出库
     */
    @Resource
    private PickingCompleteDetailMapper pickingCompleteDetailMapper;

    /**
     * 采购退货
     */
    @Resource
    private PickingPurchaseDetailMapper pickingPurchaseDetailMapper;

    /**
     * 其他出库
     */
    @Resource
    private PickingRestDetailMapper pickingRestDetailMapper;

    /**
     * 采购入库
     */
    @Resource
    private PurchaseReceiptDetailMapper purchaseReceiptDetailMapper;

    /**
     * 销售退货
     */
    @Resource
    private SalesReturnDetailMapper salesReturnDetailMapper;

    /**
     * 生产退料
     */
    @Resource
    private ProductionMaterialReturnDetailMapper productionMaterialReturnDetailMapper;

    /**
     * 完工入库
     */
    @Resource
    private WipCompletionDetailMapper wipCompletionDetailMapper;

    /**
     * 其他入库
     */
    @Resource
    private MiscellaneousReceiptDetailMapper miscellaneousReceiptDetailMapper;

    /**
     * 库存日志
     */
    @Resource
    private OutboundLogMapper outboundLogMapper;

    /**
     * 公共物料
     */
    @Resource
    private PublicGoodsMapper publicGoodsMapper;

    /**
     * 调拨单信息
     */
    @Resource
    private AllotManagementDetailMapper allotManagementDetailMapper;

    /**
     * 盘点物料明细
     */
    @Resource
    private CheckManagementMaterialDetailMapper checkManagementMaterialDetailMapper;

    /**
     * 根据母卷号码查询库存信息
     *
     * @param masterVolumeNumber
     * @return
     */
    @Override

    public MasterVolumeDto selectMasterVolumeList(String masterVolumeNumber) {

        // 根据母卷号码查询库存信息
        MasterVolumeDto masterVolumeDto = wmsStockInfoMapper.selectMasterVolumeList(masterVolumeNumber);
        if (masterVolumeDto == null) {
            throw new GlobalException("库存不存在该母卷号码信息");
        }
        return masterVolumeDto;
    }

    /**
     * 根据母卷号码修改库存的卷长
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    public int updateStockInfoById(WmsStockInfoVo wmsStockInfoVo) {
        return wmsStockInfoMapper.updateStockInfoById(wmsStockInfoVo);
    }

    /**
     * 远程调用 删除库存信息
     *
     * @param truncationMasterVolumeNumber
     * @return
     */
    @Override
    public int deleteStockInfoById(String truncationMasterVolumeNumber) {
        return wmsStockInfoMapper.deleteStockInfoById(truncationMasterVolumeNumber);
    }

    /**
     * 根据物料编码和批次号获取仓库信息
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
//    @DataScope(deptAlias = "d")
    public List<WmsStockInfoDto> getStockInfo(WmsStockInfoVo wmsStockInfoVo) throws ParseException {
        List<WmsStockInfoDto> stockInfoList = wmsStockInfoMapper.getStockInfoList(wmsStockInfoVo);
        if (stockInfoList.size() < 1) {
            return new ArrayList<>();
        }
        for (WmsStockInfoDto entity : stockInfoList) {
            //获取入库时间
            Date wsiReveiveTime = entity.getWsiReveiveTime();
            //获取复检天数
            int materialInspection = entity.getMaterialInspection();

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(wsiReveiveTime);
            calendar.add(Calendar.DAY_OF_MONTH, +materialInspection);
            Date time = calendar.getTime();
            //判断当前时间是否大于添加天数之后的时间
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String time2 = simpleDateFormat.format(time);
            String time3 = simpleDateFormat.format(new Date());
            if (time2.compareTo(time3) > 0) {
                entity.setIsOutTime(2);
                entity.setMaturityTime(time);
            } else {
                entity.setMaturityTime(time);
                entity.setIsOutTime(1);
            }
        }
        return stockInfoList;
    }

    /**
     * 根据物料号码修改单据状态
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateStatus(WmsStockInfoVo wmsStockInfoVo) {

        List<String> materialNumberList = wmsStockInfoVo.getMaterialNumberList();

        List<WmsStockInfo> wmsStockInfoList = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().in(WmsStockInfo::getWsiMaterialNumber, materialNumberList));
        for (WmsStockInfo entity : wmsStockInfoList) {
            entity.setWsiMaterialStatus(wmsStockInfoVo.getWsiMaterialStatus());
        }
        return updateBatchById(wmsStockInfoList);
    }

    /**
     * 查询仓库信息（品质检验冻结查询）
     *
     * @param qualityFreezeVo
     * @return
     */
    @Override
    public List<WmsStockInfoDto> getFreezeStockList(QualityFreezeVo qualityFreezeVo) {
        if (qualityFreezeVo.getStartTime() == null && qualityFreezeVo.getEndTime() == null && qualityFreezeVo.getWsiConnectNum() == null && qualityFreezeVo.getWsiMaterialCode() == null && qualityFreezeVo.getWsiMaterialNumber() == null) {
            List<WmsStockInfoDto> objects = new ArrayList<>();
            return objects;
        } else {
            List<WmsStockInfoDto> freezeStockList = wmsStockInfoMapper.getFreezeStockList(qualityFreezeVo);
            return freezeStockList;
        }
    }

    /**
     * 仓库状态批量修改
     *
     * @param warehouseStatusUpdateVo
     * @return
     */
    @Override
    public boolean getUpdate(WarehouseStatusUpdateVo warehouseStatusUpdateVo) {
        List<WmsStockInfo> wmsStockInfoList = null;
        if (warehouseStatusUpdateVo.getIds() != null) {
            wmsStockInfoList = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().in(WmsStockInfo::getId, warehouseStatusUpdateVo.getIds()));
            for (WmsStockInfo entity : wmsStockInfoList) {
//                //获取入库时间
//                Date wsiReveiveTime = entity.getWsiReveiveTime();
//                //获取复检天数
//                List<PublicGoods> publicGoods = publicGoodsMapper.selectList(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, entity.getWsiMaterialCode()));
//                if (publicGoods.size() > 0) {
//                    int materialInspection = publicGoods.get(0).getMaterialInspection();
//
//                    Calendar calendar = Calendar.getInstance();
//                    calendar.setTime(wsiReveiveTime);
//                    calendar.add(Calendar.DAY_OF_MONTH, +materialInspection);
//                    Date time = calendar.getTime();
//                    entity.setWsiRecheckDate(time);
//                }
                entity.setWsiRecheckDate(new Date());
                if (warehouseStatusUpdateVo.getStatusValue() != 0) {
                    entity.setWsiMaterialStatus(warehouseStatusUpdateVo.getStatusValue());
                }
                if (warehouseStatusUpdateVo.getFreeValue() != null) {
                    entity.setWsiFreezeInfo(warehouseStatusUpdateVo.getFreeValue());
                }
                if (warehouseStatusUpdateVo.getMaterialGradeValue() != 0) {
                    entity.setWsiMaterialGrade(String.valueOf(warehouseStatusUpdateVo.getMaterialGradeValue()));
                }
            }
        }

        if (warehouseStatusUpdateVo.getMaterialNumberList() != null) {
            List<String> materialNumberList = warehouseStatusUpdateVo.getMaterialNumberList();
            wmsStockInfoList = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().in(WmsStockInfo::getWsiMaterialNumber, materialNumberList));
            for (WmsStockInfo entity : wmsStockInfoList) {
                if (warehouseStatusUpdateVo.getStatusValue() != 0) {
                    entity.setWsiMaterialStatus(warehouseStatusUpdateVo.getStatusValue());
                }
                if (warehouseStatusUpdateVo.getFreeValue() != null) {
                    entity.setWsiFreezeInfo(warehouseStatusUpdateVo.getFreeValue());
                }
                if (warehouseStatusUpdateVo.getMaterialGradeValue() != 0) {
                    entity.setWsiMaterialGrade(String.valueOf(warehouseStatusUpdateVo.getMaterialGradeValue()));
                }
            }
        }
        return updateBatchById(wmsStockInfoList);
    }

    /**
     * 盘点库存汇总
     *
     * @return checkStockVo
     */
    @Override
    public List<WmsStockInfoSumDto> sumStock(CheckStockVo checkStockVo) {
        return wmsStockInfoMapper.sumStockList(checkStockVo);
    }

    /**
     * 库存明细列表
     *
     * @return
     */
    @Override
    public List<WmsStockInfoDto> getList(CheckStockVo checkStockVo) {
        return wmsStockInfoMapper.getStockList(checkStockVo);
    }

    /**
     * 盘点中物料
     *
     * @return
     */
    @Override
    public List<WmsStockInfoDto> getAllotList(CheckStockVo checkStockVo) {
        return wmsStockInfoMapper.getAllotList(checkStockVo);
    }

    /**
     * 库存新增
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    public boolean add(WmsStockInfoVo wmsStockInfoVo) {
        WmsStockInfo wmsStockInfo = new WmsStockInfo();
        BeanUtils.copyProperties(wmsStockInfoVo, wmsStockInfo);
        wmsStockInfo.setWsiLength(String.valueOf(wmsStockInfoVo.getWsiLength()));
        wmsStockInfo.setWsiProducedDate(wmsStockInfoVo.getWsiProducedDate());
        wmsStockInfo.setWsiReveiveTime(wmsStockInfoVo.getWsiReveiveTime());
        wmsStockInfo.setWsiLength(String.valueOf(wmsStockInfoVo.getWsiLength()));
        wmsStockInfo.setWsiProducedStep(wmsStockInfoVo.getWsiProducedStep());
        return save(wmsStockInfo);
    }

    /**
     * 类别加编码获取仓库数据
     *
     * @param materialNumber
     * @return
     */
    @Override
    public List<WmsStockInfoDto> getDataByCategoryAndCode(String materialNumber) {
        List<String> numberList = Arrays.asList(materialNumber.split(","));


        List<WmsStockInfoDto> stockInfoList = wmsStockInfoMapper.getDataByCategoryAndCode(numberList);

        if (stockInfoList.size() < 1) {
            throw new GlobalException("未查询到对应的在库物料");
        }

        for (WmsStockInfoDto entity : stockInfoList) {
            //获取入库时间
            Date wsiReveiveTime = entity.getWsiReveiveTime();
            //获取复检天数
            int materialInspection = entity.getMaterialInspection();

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(wsiReveiveTime);
            calendar.add(Calendar.DAY_OF_MONTH, +materialInspection);
            Date time = calendar.getTime();
            //判断当前时间是否大于添加天数之后的时间
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String time2 = simpleDateFormat.format(time);
            String time3 = simpleDateFormat.format(new Date());
            if (time2.compareTo(time3) > 0) {
                entity.setIsOutTime(2);
                entity.setMaturityTime(time);
            } else {
                entity.setIsOutTime(1);
                entity.setMaturityTime(time);
            }
        }

        return stockInfoList;
    }

    /**
     * 修正水刺母卷
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    public boolean updateSpunlace(WmsStockInfoVo wmsStockInfoVo) {
        //通过母卷号码查出库存信息
        WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, wmsStockInfoVo.getWsiMaterialNumber()));

        //修改毛重
        wmsStockInfo.setWsiGorssWeight(wmsStockInfoVo.getWsiGorssWeight());
        //修改净重
        wmsStockInfo.setWsiNetWeight(wmsStockInfoVo.getWsiNetWeight());
        //修改幅宽
        wmsStockInfo.setWsiWidth(wmsStockInfoVo.getWsiWidth());
        //修改卷长
        wmsStockInfo.setWsiLength(String.valueOf(wmsStockInfoVo.getWsiLength()));
        //修改卷径
        wmsStockInfo.setWsiDiameter(wmsStockInfoVo.getWsiDiameter());
        //修改厚度
        wmsStockInfo.setWsiThick(wmsStockInfoVo.getWsiThick());
        //修改克重
        wmsStockInfo.setWsiGrawWeight(wmsStockInfoVo.getWsiGrawWeight());
        //修改接头
        wmsStockInfo.setWsiJoint(wmsStockInfoVo.getWsiJoint());
        return updateById(wmsStockInfo);
    }

    /**
     * 返工出库新增（状态为返工）
     *
     * @param moStockInfoVo
     * @return
     */
    @Override
    public List<MoStockDto> getStockInfoMo(MoStockInfoVo moStockInfoVo) {
        List<MoStockDto> list = wmsStockInfoMapper.getMoStockInfo(moStockInfoVo);
        return list;
    }

    /**
     * 采购入库单
     *
     * @param purchaseStockVo
     */
    @Override
    public List<MoStockDto> getPurchase(PurchaseStockVo purchaseStockVo) {
        List<MoStockDto> list = wmsStockInfoMapper.getPurchase(purchaseStockVo);
        return list;
    }

    /**
     * 根据物料编码获取该物料在仓库中的净重之和(feign调用)
     *
     * @param materialCode
     * @return
     */
    @Override
    public String getSum(String materialCode) {

        List<WmsStockInfo> wmsStockInfoList = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialCode, materialCode).eq(WmsStockInfo::getWsiMaterialStatus, 2));
        BigDecimal bigDecimal = new BigDecimal(0);
        for (WmsStockInfo entity : wmsStockInfoList) {
            bigDecimal = bigDecimal.add(new BigDecimal(String.valueOf(entity.getWsiNetWeight())));
        }
        return bigDecimal.toString();
    }


    /**
     * 根据物料编码获取库存重量（feign调用 委外入库页面使用）
     *
     * @param materialCode
     * @return
     */
    @Override
    public double getStockWeight(String materialCode) {

        List<WmsStockInfo> wmsStockInfoList = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialCode, materialCode));
        BigDecimal bigDecimal = new BigDecimal(0);
        for (WmsStockInfo entity : wmsStockInfoList) {
            bigDecimal = bigDecimal.add(new BigDecimal(String.valueOf(entity.getWsiNetWeight())));
        }
        return Double.parseDouble(bigDecimal.toString());
    }

    /**
     * 根据物料号码修改库存状态为冻结
     *
     * @param materialNumber
     */
    @Override
    public void updateStatusThaw(String materialNumber) {
        WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, materialNumber));
        if (wmsStockInfo != null) {
            wmsStockInfo.setWsiFreezeInfo("1");
            updateById(wmsStockInfo);
        }
    }

    /**
     * 修改库存状态更新为“在库”
     *
     * @param updateStatusVo
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean updateStockStatus(UpdateStatusVo updateStatusVo) {

        List<WmsStockInfo> wmsStockInfoList = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().in(WmsStockInfo::getWsiMaterialNumber, updateStatusVo.getMaterialNumberList()));
        for (WmsStockInfo entity : wmsStockInfoList) {
            entity.setWsiMaterialStatus(2);
        }
        return updateBatchById(wmsStockInfoList);
    }

    /**
     * 查询基础信息（feign调用 物料追溯页面使用）
     *
     * @param wsiCategory, wsiMaterialNumber
     * @return
     */
    @Override
    public List<RetrospectManageDto> getRetrospectManageList(Long wsiCategory, String wsiMaterialNumber) {

        // 类别
        List<SysDictData> qualityCategory = DictUtils.getDictCache("quality_category");
        Map<String, String> qualityCategoryMap = qualityCategory.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 物料等级
        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 库存状态
        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 冻结标识
        List<SysDictData> freezeInfo = DictUtils.getDictCache("wms_stock_info_freeze_info");
        Map<String, String> freezeInfoMap = freezeInfo.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        List<RetrospectManageDto> list = new ArrayList<>();

        // 库存表
        List<RetrospectManageDto> retrospectManageList = wmsStockInfoMapper.getRetrospectManageList(wsiCategory, wsiMaterialNumber);

        if (retrospectManageList.size() > 0) {
            for (RetrospectManageDto retrospectManageDto : retrospectManageList) {
                AjaxResult ajaxResult = feignService.selectCodingRulesById(retrospectManageDto.getWsiMaterialType());
                MaterialCodingDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), MaterialCodingDto.class);

                // 数据字典
                retrospectManageDto.setWsiCategoryDict(qualityCategoryMap.get(retrospectManageDto.getWsiCategory()));
                retrospectManageDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(retrospectManageDto.getWsiMaterialGrade()));
                retrospectManageDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(retrospectManageDto.getWsiMaterialStatus()));
                retrospectManageDto.setWsiFreezeInfoDict(freezeInfoMap.get(retrospectManageDto.getWsiFreezeInfo()));
                retrospectManageDto.setWsiMaterialTypeDict(data.getCodingRules());
                list.add(retrospectManageDto);
            }
        } else {
            // 库存日志表
            List<RetrospectManageDto> retrospectManageInfo = wmsStockInfoMapper.selectRetrospectManageInfo(wsiCategory, wsiMaterialNumber);
            for (RetrospectManageDto retrospectManageDto : retrospectManageInfo) {
                AjaxResult ajaxResult = feignService.selectCodingRulesById(retrospectManageDto.getWsiMaterialType());
                MaterialCodingDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), MaterialCodingDto.class);

                // 数据字典
                retrospectManageDto.setWsiCategoryDict(qualityCategoryMap.get(retrospectManageDto.getWsiCategory()));
                retrospectManageDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(retrospectManageDto.getWsiMaterialGrade()));
                retrospectManageDto.setWsiMaterialStatusDict("已出库");
                retrospectManageDto.setWsiFreezeInfoDict(freezeInfoMap.get(retrospectManageDto.getWsiFreezeInfo()));
                retrospectManageDto.setWsiMaterialTypeDict(data.getCodingRules());
                list.add(retrospectManageDto);
            }
        }


        return list;
    }

    /**
     * 查询同批次物料 （feign调用 物料追溯页面使用）
     *
     * @param wsiMaterialNumber 根据物料号码查询
     * @return
     */
    @Override
    public List<RetrospectMaterialDto> getRetrospectMaterialList(String wsiMaterialNumber) {

        // 出库总集合
        List<RetrospectMaterialDto> list = new ArrayList<>();
        // 物料等级
        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 库存状态
        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 查询物料批次号 库存表
        RetrospectMaterialDto retrospectMaterialList = wmsStockInfoMapper.getRetrospectMaterialList(wsiMaterialNumber);

        // 查询物料批次号 库存日志表
        RetrospectMaterialDto retrospectMaterialListLog = wmsStockInfoMapper.getRetrospectMaterialListLog(wsiMaterialNumber);

        if (retrospectMaterialList != null) {

            List<RetrospectMaterialDto> list1 = new ArrayList<>();
            List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
            for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
                RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                // 物料号码
                retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
                // 净重
                retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
                // 库存状态
                retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
                retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
                retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
                retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
                list1.add(retrospectMaterialDto);
            }

            List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
            for (OutboundLog outboundLog : outboundLogs) {
                RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                // 物料号码
                retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
                // 净重
                retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
                // 库存状态
                retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
                retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
                retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
                retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
                list1.add(retrospectMaterialDto);
            }
            list.addAll(list1);

        } else {

            List<RetrospectMaterialDto> list1 = new ArrayList<>();
            List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
            for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
                RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                // 物料号码
                retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
                // 净重
                retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
                // 库存状态
                retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
                retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
                retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
                retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
                list1.add(retrospectMaterialDto);
            }

            List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
            for (OutboundLog outboundLog : outboundLogs) {
                RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                // 物料号码
                retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
                // 净重
                retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
                // 库存状态
                retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
                retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
                retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
                retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
                list1.add(retrospectMaterialDto);
            }
            list.addAll(list1);
        }

        ArrayList<RetrospectMaterialDto> collect = list.stream().collect(
                Collectors.collectingAndThen(
                        Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(RetrospectMaterialDto::getWsiMaterialNumber))),
                        ArrayList::new));

        // 去除重复数据
        return collect;
    }

    /**
     * 产品追溯 同批次物料
     *
     * @param wsiMaterialNumber 根据物料号码查询
     * @return
     */
    @Override
    public List<RetrospectMaterialDto> getRetrospectProductList(String codingType, String wsiMaterialNumber) {

        // 出库总集合
        List<RetrospectMaterialDto> list = new ArrayList<>();
        // 物料等级
        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 库存状态
        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));


        // 如果是成品
        if (codingType.equals("1")) {

            // 查询物料批次号 库存表
            RetrospectMaterialDto retrospectMaterialList = wmsStockInfoMapper.getRetrospectMaterialList(wsiMaterialNumber);

            // 查询物料批次号 库存日志表
            RetrospectMaterialDto retrospectMaterialListLog = wmsStockInfoMapper.getRetrospectMaterialListLog(wsiMaterialNumber);

            if (retrospectMaterialList != null) {

                List<RetrospectMaterialDto> list1 = new ArrayList<>();
                List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
                for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                    // 物料号码
                    retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
                    // 净重
                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
                    // 库存状态
                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
                    retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
                    retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
                    list1.add(retrospectMaterialDto);
                }

                List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
                for (OutboundLog outboundLog : outboundLogs) {
                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                    // 物料号码
                    retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
                    // 净重
                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
                    // 库存状态
                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
                    retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
                    retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
                    list1.add(retrospectMaterialDto);
                }
                list.addAll(list1);

            } else {

                List<RetrospectMaterialDto> list1 = new ArrayList<>();
                List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
                if (wmsStockInfos.size() > 0) {
                    for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
                        RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                        // 物料号码
                        retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
                        // 净重
                        retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
                        // 库存状态
                        retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
                        retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
                        retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
                        retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
                        list1.add(retrospectMaterialDto);
                    }

                }

                List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
                for (OutboundLog outboundLog : outboundLogs) {
                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                    // 物料号码
                    retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
                    // 净重
                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
                    // 库存状态
                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
                    retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
                    retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
                    list1.add(retrospectMaterialDto);
                }
                list.addAll(list1);
            }

        }
        // 如果是母卷
        if (codingType.equals("2")) {
            // 查询物料批次号 库存表
            RetrospectMaterialDto retrospectMaterialList = wmsStockInfoMapper.getRetrospectMaterialList(wsiMaterialNumber);

            // 查询物料批次号 库存日志表
            RetrospectMaterialDto retrospectMaterialListLog = wmsStockInfoMapper.getRetrospectMaterialListLog(wsiMaterialNumber);

            if (retrospectMaterialList != null) {

                List<RetrospectMaterialDto> list1 = new ArrayList<>();
                List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
                for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                    // 物料号码
                    retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
                    // 净重
                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
                    // 库存状态
                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
                    retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
                    retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
                    list1.add(retrospectMaterialDto);
                }

                List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
                for (OutboundLog outboundLog : outboundLogs) {
                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                    // 物料号码
                    retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
                    // 净重
                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
                    // 库存状态
                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
                    retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
                    retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
                    list1.add(retrospectMaterialDto);
                }
                list.addAll(list1);

            } else {

                List<RetrospectMaterialDto> list1 = new ArrayList<>();
                List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
                for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                    // 物料号码
                    retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
                    // 净重
                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
                    // 库存状态
                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
                    retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
                    retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
                    list1.add(retrospectMaterialDto);
                }

                List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
                for (OutboundLog outboundLog : outboundLogs) {
                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                    // 物料号码
                    retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
                    // 净重
                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
                    // 库存状态
                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
                    retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
                    retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
                    list1.add(retrospectMaterialDto);
                }
                list.addAll(list1);
            }
        }

        // 如果是小卷
        if (codingType.equals("3")) {
            AjaxResult ajaxResult1 = feignProductionService.selectRollPackingHistoryInfo(wsiMaterialNumber);
            RollPackingHistoryDto data1 = JSON.parseObject(JSON.toJSONString(ajaxResult1.get("data")), RollPackingHistoryDto.class);

            // 查询物料批次号 库存表
            RetrospectMaterialDto retrospectMaterialList = wmsStockInfoMapper.getRetrospectMaterialList(data1.getMasterVolumeNumber());

            // 查询物料批次号 库存日志表
            RetrospectMaterialDto retrospectMaterialListLog = wmsStockInfoMapper.getRetrospectMaterialListLog(data1.getMasterVolumeNumber());

            if (retrospectMaterialList != null) {

                List<RetrospectMaterialDto> list1 = new ArrayList<>();
                List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
                for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                    // 物料号码
                    retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
                    // 净重
                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
                    // 库存状态
                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
                    retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
                    retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
                    list1.add(retrospectMaterialDto);
                }

                List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialList.getWsiMaterialBatch()));
                for (OutboundLog outboundLog : outboundLogs) {
                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                    // 物料号码
                    retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
                    // 净重
                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
                    // 库存状态
                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
                    retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
                    retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
                    list1.add(retrospectMaterialDto);
                }
                list.addAll(list1);

            } else {

                List<RetrospectMaterialDto> list1 = new ArrayList<>();
                List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
                for (WmsStockInfo wmsStockInfo : wmsStockInfos) {
                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                    // 物料号码
                    retrospectMaterialDto.setWsiMaterialNumber(wmsStockInfo.getWsiMaterialNumber());
                    // 净重
                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(wmsStockInfo.getWsiNetWeight()));
                    // 库存状态
                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(wmsStockInfo.getWsiMaterialStatus()));
                    retrospectMaterialDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(String.valueOf(wmsStockInfo.getWsiMaterialStatus())));
                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(wmsStockInfo.getWsiMaterialGrade()));
                    retrospectMaterialDto.setWsiProducedDate(wmsStockInfo.getWsiProducedDate());
                    list1.add(retrospectMaterialDto);
                }

                List<OutboundLog> outboundLogs = outboundLogMapper.selectList(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialBatch, retrospectMaterialListLog.getWsiMaterialBatch()));
                for (OutboundLog outboundLog : outboundLogs) {
                    RetrospectMaterialDto retrospectMaterialDto = new RetrospectMaterialDto();
                    // 物料号码
                    retrospectMaterialDto.setWsiMaterialNumber(outboundLog.getWsiMaterialNumber());
                    // 净重
                    retrospectMaterialDto.setWsiNetWeight(String.valueOf(outboundLog.getWsiNetWeight()));
                    // 库存状态
                    retrospectMaterialDto.setWsiMaterialStatus(String.valueOf(outboundLog.getWsiMaterialStatus()));
                    retrospectMaterialDto.setWsiMaterialStatusDict("已出库");
                    retrospectMaterialDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(outboundLog.getWsiMaterialGrade()));
                    retrospectMaterialDto.setWsiProducedDate(outboundLog.getWsiProducedDate());
                    list1.add(retrospectMaterialDto);
                }
                list.addAll(list1);
            }
        }

        ArrayList<RetrospectMaterialDto> collect = list.stream().collect(
                Collectors.collectingAndThen(
                        Collectors.toCollection(() -> new TreeSet<>(Comparator.comparing(RetrospectMaterialDto::getWsiMaterialNumber))),
                        ArrayList::new));
        // 去除重复数据
        return collect;
    }

    /**
     * 物料履历
     *
     * @param wsiMaterialNumber
     * @return
     */
    @Override
    public List<MaterialResumeDto> MaterialResumeList(Long wsiCategory, String wsiMaterialNumber) {

        List<MaterialResumeDto> list = new ArrayList<>();

        // 当类型为原料
        if (wsiCategory == 1) {
            // 来料打印
            List<MaterialResumeDto> materialResumeDtoList = new ArrayList<>();
            List<MaterialResumeDto> materialResumeDtos = wmsStockInfoMapper.getIncomingPersonalDetails(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : materialResumeDtos) {
                materialResumeDto.setJobTypeDict("采购打印");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                materialResumeDtoList.add(materialResumeDto);

            }
            // 采购入库
            List<MaterialResumeDto> purchasePersonalDetailsList = new ArrayList<>();
            List<MaterialResumeDto> purchasePersonalDetails = wmsStockInfoMapper.getPurchasePersonalDetails(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : purchasePersonalDetails) {
                materialResumeDto.setJobTypeDict("扫码/批次入库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                purchasePersonalDetailsList.add(materialResumeDto);
            }

            // 生产退料
            List<MaterialResumeDto> productionReturnPersonalDetailsList = new ArrayList<>();
            List<MaterialResumeDto> productionReturnPersonalDetails = wmsStockInfoMapper.getProductionReturnPersonalDetails(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : productionReturnPersonalDetails) {
                materialResumeDto.setJobTypeDict("扫码入库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                productionReturnPersonalDetailsList.add(materialResumeDto);
            }

            // 其他入库
            List<MaterialResumeDto> otherWarehousingPersonalDetailsList = new ArrayList<>();
            List<MaterialResumeDto> otherWarehousingPersonalDetails = wmsStockInfoMapper.getOtherWarehousingPersonalDetails(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : otherWarehousingPersonalDetails) {
                materialResumeDto.setJobTypeDict("扫码入库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                otherWarehousingPersonalDetailsList.add(materialResumeDto);
            }

            // 生产领料
            List<MaterialResumeDto> pickingPersonalDetailsList = new ArrayList<>();
            List<MaterialResumeDto> pickingPersonalDetails = wmsStockInfoMapper.getPickingPersonalDetails(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : pickingPersonalDetails) {
                materialResumeDto.setJobTypeDict("扫码/批次出库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                pickingPersonalDetailsList.add(materialResumeDto);
            }

            // 委外发货
            List<MaterialResumeDto> outsourcingShipmentPersonalList = new ArrayList<>();
            List<MaterialResumeDto> outsourcingShipmentPersonal = wmsStockInfoMapper.getOutsourcingShipmentPersonal(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : outsourcingShipmentPersonal) {
                materialResumeDto.setJobTypeDict("扫码/批次出库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                outsourcingShipmentPersonalList.add(materialResumeDto);
            }

            // 采购退货
            List<MaterialResumeDto> purchaseReturnList = new ArrayList<>();
            List<MaterialResumeDto> purchaseReturn = wmsStockInfoMapper.getPurchaseReturn(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : purchaseReturn) {
                materialResumeDto.setJobTypeDict("扫码/批次出库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                purchaseReturnList.add(materialResumeDto);
            }

            // 其他出库
            List<MaterialResumeDto> otherOutboundList = new ArrayList<>();
            List<MaterialResumeDto> otherOutbound = wmsStockInfoMapper.getOtherOutbound(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : otherOutbound) {
                materialResumeDto.setJobTypeDict("扫码/批次出库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                otherOutboundList.add(materialResumeDto);
            }


            // 水刺制令单
            List<MaterialResumeDto> spunlaceOrderList = new ArrayList<>();
            AjaxResult materialNumber1 = feignProductionService.getMaterialNumberInfo(wsiMaterialNumber);
            FeedRecordDetailsDto feedRecordDetailsData1 = JSON.parseObject(JSON.toJSONString(materialNumber1.get("data")), FeedRecordDetailsDto.class);
            if (feedRecordDetailsData1 != null && feedRecordDetailsData1.getFeedType() != null) {
                if (feedRecordDetailsData1.getFeedType() == 1) {
                    MaterialResumeDto materialResumeDto1 = new MaterialResumeDto();
                    materialResumeDto1.setJobTypeDict("扫码投料");
                    materialResumeDto1.setDocumentType("水刺制令单");
                    materialResumeDto1.setConnectDoc(feedRecordDetailsData1.getFeedOrderNumber());
                    materialResumeDto1.setCreateUser(feedRecordDetailsData1.getCreateBy());
                    materialResumeDto1.setCreateTime(feedRecordDetailsData1.getCreateTime());
                    spunlaceOrderList.add(materialResumeDto1);
                } else {
                    MaterialResumeDto materialResumeDto2 = new MaterialResumeDto();
                    materialResumeDto2.setJobTypeDict("扫码投料");
                    materialResumeDto2.setDocumentType("脱脂制令单");
                    materialResumeDto2.setConnectDoc(feedRecordDetailsData1.getFeedOrderNumber());
                    materialResumeDto2.setCreateUser(feedRecordDetailsData1.getCreateBy());
                    materialResumeDto2.setCreateTime(feedRecordDetailsData1.getCreateTime());
                    spunlaceOrderList.add(materialResumeDto2);
                }
            }


//            // 脱脂制令单
//            List<MaterialResumeDto> feedRecordDetailsDataList = new ArrayList<>();
//            AjaxResult materialNumber = feignProductionService.getMaterialNumberInfo(wsiMaterialNumber);
//            FeedRecordDetailsDto feedRecordDetailsData = JSON.parseObject(JSON.toJSONString(materialNumber.get("data")), FeedRecordDetailsDto.class);
//
//            if (feedRecordDetailsData.getFeedType() == 2) {
//                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                materialResumeDto.setJobTypeDict("扫码投料");
//                materialResumeDto.setDocumentType("水刺制令单");
//                materialResumeDto.setConnectDoc(feedRecordDetailsData.getFeedOrderNumber());
//                materialResumeDto.setCreateUser(feedRecordDetailsData.getCreateBy());
//                materialResumeDto.setCreateTime(feedRecordDetailsData.getCreateTime());
//                feedRecordDetailsDataList.add(materialResumeDto);
//            }

            // 调拨单信息
            List<MaterialResumeDto> allotManagementDetailInfoList = new ArrayList<>();
            AllotManagementDetailDto allotManagementDetailInfo = allotManagementDetailMapper.getAllotManagementDetailInfo(wsiMaterialNumber);
            if (allotManagementDetailInfo != null && allotManagementDetailInfo.getAllotDoc() != null) {
                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                materialResumeDto.setJobTypeDict("调拨管理");
                materialResumeDto.setDocumentType("调拨单信息");
                materialResumeDto.setConnectDoc(allotManagementDetailInfo.getAllotDoc());
                materialResumeDto.setCreateUser(allotManagementDetailInfo.getDepositorIn());
                materialResumeDto.setCreateTime(allotManagementDetailInfo.getReviceTime());
                allotManagementDetailInfoList.add(materialResumeDto);
            }

            // 盘点单信息
            List<MaterialResumeDto> checkDetailList = new ArrayList<>();
            List<CheckManagmentMaterialDto> checkManagmentMaterialInfo = checkManagementMaterialDetailMapper.getCheckManagmentMaterialInfo(wsiMaterialNumber);
            for (CheckManagmentMaterialDto checkManagmentMaterialDto : checkManagmentMaterialInfo) {
                if (checkManagmentMaterialDto.getCheckDoc() != null) {
                    MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                    materialResumeDto.setJobTypeDict("盘点管理");
                    materialResumeDto.setDocumentType("盘点单信息");
                    materialResumeDto.setConnectDoc(checkManagmentMaterialDto.getCheckDoc());
                    materialResumeDto.setCreateUser(checkManagmentMaterialDto.getCreateUser());
                    materialResumeDto.setCreateTime(checkManagmentMaterialDto.getCreateTime());
                    checkDetailList.add(materialResumeDto);
                }
            }


            list.addAll(materialResumeDtoList);
            list.addAll(purchasePersonalDetailsList);
            list.addAll(productionReturnPersonalDetailsList);
            list.addAll(otherWarehousingPersonalDetailsList);
            list.addAll(pickingPersonalDetailsList);
            list.addAll(outsourcingShipmentPersonalList);
            list.addAll(purchaseReturnList);
            list.addAll(otherOutboundList);
            list.addAll(spunlaceOrderList);
//            list.addAll(feedRecordDetailsDataList);
            list.addAll(allotManagementDetailInfoList);
            list.addAll(checkDetailList);
        }
        // 当类型为半成品
        if (wsiCategory == 3) {

            // 生产退料
            List<MaterialResumeDto> productionReturnPersonalDetailsList = new ArrayList<>();
            List<MaterialResumeDto> productionReturnPersonalDetails = wmsStockInfoMapper.getProductionReturnPersonalDetails(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : productionReturnPersonalDetails) {
                materialResumeDto.setJobTypeDict("扫码入库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                productionReturnPersonalDetailsList.add(materialResumeDto);
            }

            // 完工入库
            List<MaterialResumeDto> wipCompletionInfoList = new ArrayList<>();
            List<MaterialResumeDto> wipCompletionList = wmsStockInfoMapper.getWipCompletionList(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : wipCompletionList) {
                materialResumeDto.setJobTypeDict("扫码/批次入库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                wipCompletionInfoList.add(materialResumeDto);
            }

            // 委外入库
            List<MaterialResumeDto> subcontractReceiptListList = new ArrayList<>();
            List<MaterialResumeDto> subcontractReceiptList = wmsStockInfoMapper.getSubcontractReceiptList(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : subcontractReceiptList) {
                materialResumeDto.setJobTypeDict("扫码/批次入库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                subcontractReceiptListList.add(materialResumeDto);
            }

            // 来料打印
            List<MaterialResumeDto> materialResumeDtoList = new ArrayList<>();
            List<MaterialResumeDto> materialResumeDtos = wmsStockInfoMapper.getIncomingPersonalDetails(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : materialResumeDtos) {
                materialResumeDto.setJobTypeDict("委外打印");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                materialResumeDtoList.add(materialResumeDto);
            }

            // 其他入库
            List<MaterialResumeDto> otherWarehousingPersonalDetailsList = new ArrayList<>();
            List<MaterialResumeDto> otherWarehousingPersonalDetails = wmsStockInfoMapper.getOtherWarehousingPersonalDetails(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : otherWarehousingPersonalDetails) {
                materialResumeDto.setJobTypeDict("扫码入库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                otherWarehousingPersonalDetailsList.add(materialResumeDto);
            }

            // 生产领料
            List<MaterialResumeDto> pickingPersonalDetailsList = new ArrayList<>();
            List<MaterialResumeDto> pickingPersonalDetails = wmsStockInfoMapper.getPickingPersonalDetails(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : pickingPersonalDetails) {
                materialResumeDto.setJobTypeDict("扫码/批次出库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                pickingPersonalDetailsList.add(materialResumeDto);
            }

            // 返工出库
            List<MaterialResumeDto> pickingCompleteList = new ArrayList<>();
            List<MaterialResumeDto> pickingCompleteInfoList = wmsStockInfoMapper.getPickingCompleteInfoList(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : pickingCompleteInfoList) {
                materialResumeDto.setJobTypeDict("扫码/批次出库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                pickingCompleteList.add(materialResumeDto);
            }

            // 委外发货
            List<MaterialResumeDto> outsourcingShipmentPersonalList = new ArrayList<>();
            List<MaterialResumeDto> outsourcingShipmentPersonal = wmsStockInfoMapper.getOutsourcingShipmentPersonal(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : outsourcingShipmentPersonal) {
                materialResumeDto.setJobTypeDict("扫码/批次出库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                outsourcingShipmentPersonalList.add(materialResumeDto);
            }

            // 委外退货
            List<MaterialResumeDto> pickingReturnsList = new ArrayList<>();
            List<MaterialResumeDto> pickingReturnsInfoList = wmsStockInfoMapper.getPickingReturnsInfoList(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : pickingReturnsInfoList) {
                materialResumeDto.setJobTypeDict("扫码/批次出库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                pickingReturnsList.add(materialResumeDto);
            }

            // 其他出库
            List<MaterialResumeDto> otherOutboundList = new ArrayList<>();
            List<MaterialResumeDto> otherOutbound = wmsStockInfoMapper.getOtherOutbound(wsiMaterialNumber);
            for (MaterialResumeDto materialResumeDto : otherOutbound) {
                materialResumeDto.setJobTypeDict("扫码/批次出库");
                materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                otherOutboundList.add(materialResumeDto);
            }


//            // 水刺制令单
//            List<MaterialResumeDto> spunlaceOrderList = new ArrayList<>();
//            // TODO 修改库存日志表
//            WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, wsiMaterialNumber));
//            // 查询投料类型
//            AjaxResult ajaxResult = feignProductionService.selectSpunlaceOrderInfo(wmsStockInfo.getWsiConnectNum());
//            if (ajaxResult != null) {
//                List<MaterialResumeDto> data = JSON.parseArray(JSON.toJSONString(ajaxResult.get("data")), MaterialResumeDto.class);
//                for (MaterialResumeDto materialResumeDto : data) {
//                    if (materialResumeDto.getDocumentType().equals("1")) {
//                        AjaxResult ajaxResult1 = feignProductionService.selectDocumentStatusInfo(wmsStockInfo.getWsiConnectNum());
//                        SpunlaceOrder data1 = JSON.parseObject(JSON.toJSONString(ajaxResult1.get("data")), SpunlaceOrder.class);
//                        materialResumeDto.setJobTypeDict("扫码投料");
//                        materialResumeDto.setDocumentType(data1.getDocumentStatus());
//                        materialResumeDto.setConnectDoc(materialResumeDto.getConnectDoc());
//                        materialResumeDto.setCreateUser(materialResumeDto.getCreateUser());
//                        materialResumeDto.setCreateTime(materialResumeDto.getCreateTime());
//                        spunlaceOrderList.add(materialResumeDto);
//                    }
//                }
//            }


//            if (wmsStockInfo == null) {
//                OutboundLog outboundLog = outboundLogMapper.selectOne(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialNumber, wsiMaterialNumber));
//                // 查询投料类型
//                AjaxResult ajaxResult1 = feignProductionService.selectSpunlaceOrderInfo(outboundLog.getWsiConnectNum());
//                List<MaterialResumeDto> data1 = JSON.parseArray(JSON.toJSONString(ajaxResult1.get("data")), MaterialResumeDto.class);
//                for (MaterialResumeDto materialResumeDto : data1) {
//                    if (materialResumeDto.getDocumentType().equals("1")) {
//                        AjaxResult ajaxResult2 = feignProductionService.selectDocumentStatusInfo(outboundLog.getWsiConnectNum());
//                        SpunlaceOrder data2 = JSON.parseObject(JSON.toJSONString(ajaxResult2.get("data")), SpunlaceOrder.class);
//                        materialResumeDto.setJobTypeDict("扫码投料");
//                        materialResumeDto.setDocumentType(data2.getDocumentStatus());
//                        materialResumeDto.setConnectDoc(materialResumeDto.getConnectDoc());
//                        materialResumeDto.setCreateUser(materialResumeDto.getCreateUser());
//                        materialResumeDto.setCreateTime(materialResumeDto.getCreateTime());
//                        spunlaceOrderList.add(materialResumeDto);
//                    }
//                }
//            }


//            List<MaterialResumeDto> detailListMaterialNumber = new ArrayList<>();
//            AjaxResult ajaxResult3 = feignProductionService.selectDetailListMaterialNumber(wsiMaterialNumber);
//            DegreasOutputDetailDto data3 = JSON.parseObject(JSON.toJSONString(ajaxResult3.get("data")), DegreasOutputDetailDto.class);
//            if (data3!=null) {
//                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
//                materialResumeDto.setJobTypeDict("扫码投料");
//                materialResumeDto.setDocumentType("水刺制令单");
//                materialResumeDto.setConnectDoc(data3.getDegreasOrderNumber());
//                materialResumeDto.setCreateUser(data3.getCreateBy());
//                materialResumeDto.setCreateTime(data3.getCreateTime());
//                detailListMaterialNumber.add(materialResumeDto);
//            }

            // 投料
            List<MaterialResumeDto> feedRecordDetailsDataList = new ArrayList<>();
            AjaxResult materialNumber = feignProductionService.getMaterialNumberInfo(wsiMaterialNumber);
            FeedRecordDetailsDto feedRecordDetailsData = JSON.parseObject(JSON.toJSONString(materialNumber.get("data")), FeedRecordDetailsDto.class);
            if (feedRecordDetailsData != null && feedRecordDetailsData.getDetailsId() != 0) {
                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                materialResumeDto.setJobTypeDict("扫码投料");
                materialResumeDto.setDocumentType("水刺制令单");
                materialResumeDto.setConnectDoc(feedRecordDetailsData.getFeedOrderNumber());
                materialResumeDto.setCreateUser(feedRecordDetailsData.getCreateBy());
                materialResumeDto.setCreateTime(feedRecordDetailsData.getCreateTime());
                feedRecordDetailsDataList.add(materialResumeDto);
            }


            // 产出打印
            List<MaterialResumeDto> degreasOutputDetailList1 = new ArrayList<>();
            AjaxResult ajaxResult1 = feignProductionService.selectMaterialNumberInfo(wsiMaterialNumber);
            DegreasOutputDetail degreasOutputDetailData = JSON.parseObject(JSON.toJSONString(ajaxResult1.get("data")), DegreasOutputDetail.class);
            if (degreasOutputDetailData.getId() != null && degreasOutputDetailData.getId() != 0) {
                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                materialResumeDto.setJobTypeDict("产出打印");
                materialResumeDto.setDocumentType("脱脂制令单");
                materialResumeDto.setConnectDoc(degreasOutputDetailData.getDegreasOrderNumber());
                materialResumeDto.setCreateUser(degreasOutputDetailData.getCreateBy());
                materialResumeDto.setCreateTime(degreasOutputDetailData.getCreateTime());
                degreasOutputDetailList1.add(materialResumeDto);
            }

            // 扫描入库
            List<MaterialResumeDto> degreasOutputDetailList = new ArrayList<>();
            AjaxResult ajaxResult2 = feignProductionService.selectMaterialNumberInfo(wsiMaterialNumber);
            DegreasOutputDetail data1 = JSON.parseObject(JSON.toJSONString(ajaxResult2.get("data")), DegreasOutputDetail.class);
            if (data1 != null && data1.getStatus() == 2) {
                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                materialResumeDto.setJobTypeDict("扫描入库");
                materialResumeDto.setDocumentType("脱脂制令单");
                materialResumeDto.setConnectDoc(data1.getDegreasOrderNumber());
                materialResumeDto.setCreateUser(data1.getOperator());
                materialResumeDto.setCreateTime(data1.getOutputTime());
                degreasOutputDetailList.add(materialResumeDto);
            }

            // 调拨单信息
            List<MaterialResumeDto> allotManagementDetailInfoList = new ArrayList<>();
            AllotManagementDetailDto allotManagementDetailInfo = allotManagementDetailMapper.getAllotManagementDetailInfo(wsiMaterialNumber);
            if (allotManagementDetailInfo != null && allotManagementDetailInfo.getAllotDoc() != null) {
                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                materialResumeDto.setJobTypeDict("调拨管理");
                materialResumeDto.setDocumentType("调拨单信息");
                materialResumeDto.setConnectDoc(allotManagementDetailInfo.getAllotDoc());
                materialResumeDto.setCreateUser(allotManagementDetailInfo.getDepositorIn());
                materialResumeDto.setCreateTime(allotManagementDetailInfo.getReviceTime());
                allotManagementDetailInfoList.add(materialResumeDto);
            }

            // 盘点单信息
            List<MaterialResumeDto> checkDetailList = new ArrayList<>();
            List<CheckManagmentMaterialDto> checkManagmentMaterialInfo = checkManagementMaterialDetailMapper.getCheckManagmentMaterialInfo(wsiMaterialNumber);
            for (CheckManagmentMaterialDto checkManagmentMaterialDto : checkManagmentMaterialInfo) {
                if (checkManagmentMaterialDto.getCheckDoc() != null) {
                    MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                    materialResumeDto.setJobTypeDict("盘点管理");
                    materialResumeDto.setDocumentType("盘点单信息");
                    materialResumeDto.setConnectDoc(checkManagmentMaterialDto.getCheckDoc());
                    materialResumeDto.setCreateUser(checkManagmentMaterialDto.getCreateUser());
                    materialResumeDto.setCreateTime(checkManagmentMaterialDto.getCreateTime());
                    checkDetailList.add(materialResumeDto);
                }
            }

            // 生产退料
            list.addAll(productionReturnPersonalDetailsList);
            // 完工入库
            list.addAll(wipCompletionInfoList);
            // 委外入库
            list.addAll(subcontractReceiptListList);
            // 来料打印
            list.addAll(materialResumeDtoList);
            // 其他入库
            list.addAll(otherWarehousingPersonalDetailsList);
            // 生产领料
            list.addAll(pickingPersonalDetailsList);
            // 返工出库
            list.addAll(pickingCompleteList);
            // 委外发货
            list.addAll(outsourcingShipmentPersonalList);
            // 委外退货
            list.addAll(pickingReturnsList);
            // 其他出库
            list.addAll(otherOutboundList);
//            // 水刺制令单
//            list.addAll(spunlaceOrderList);
            // 产出打印
            list.addAll(degreasOutputDetailList1);
            // 扫描入库
            list.addAll(degreasOutputDetailList);
//            // 扫描入库
//            list.addAll(detailListMaterialNumber);
            list.addAll(feedRecordDetailsDataList);
            list.addAll(allotManagementDetailInfoList);
            list.addAll(checkDetailList);
        }
        return list;
    }

    /**
     * 产品追溯基础信息（feign调用 产品追溯页面使用）
     *
     * @param codingType
     * @param wsiMaterialNumber
     * @return
     */
    @Override
    public List<ProductTraceabilityDto> getProductTraceabilityList(String codingType, String wsiMaterialNumber) {

        // 类别
        List<SysDictData> qualityCategory = DictUtils.getDictCache("quality_category");
        Map<String, String> qualityCategoryMap = qualityCategory.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 物料等级
        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 库存状态
        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 冻结标识
        List<SysDictData> freezeInfo = DictUtils.getDictCache("wms_stock_info_freeze_info");
        Map<String, String> freezeInfoMap = freezeInfo.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 成品称重入库状态
        List<SysDictData> weighingStatus = DictUtils.getDictCache("weighing_finished_material_product_storage_status");
        Map<String, String> weighingStatusMap = weighingStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        //生产状态
        List<SysDictData> statusArray = DictUtils.getDictCache("spunlace_output_detail_status");
        Map<String, String> statusMap = statusArray.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        List<ProductTraceabilityDto> list = new ArrayList<>();
        // 如果是成品
        if (codingType.equals("1")) {
            // 库存表
            ProductTraceabilityDto productTraceabilityList = wmsStockInfoMapper.getProductTraceabilityList(wsiMaterialNumber);

            if (productTraceabilityList != null) {
                AjaxResult ajaxResult = feignService.selectCodingRulesById(productTraceabilityList.getWsiMaterialType());
                MaterialCodingDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), MaterialCodingDto.class);
                productTraceabilityList.setWsiMaterialTypeDict(data.getCodingRules());
                // 库存状态
                productTraceabilityList.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(productTraceabilityList.getWsiMaterialStatus()));
                list.add(productTraceabilityList);
            } else {
                ProductTraceabilityDto productTraceabilityListLog = wmsStockInfoMapper.getProductTraceabilityListLog(wsiMaterialNumber);
                AjaxResult ajaxResult = feignService.selectCodingRulesById(productTraceabilityListLog.getWsiMaterialType());
                MaterialCodingDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), MaterialCodingDto.class);
                productTraceabilityListLog.setWsiMaterialTypeDict(data.getCodingRules());
                productTraceabilityListLog.setWsiMaterialStatusDict("已出库");
                list.add(productTraceabilityListLog);
            }
        }

        // 如果是母卷
        if (codingType.equals("2")) {
            AjaxResult ajaxResult = feignProductionService.selectSpunlaceDetailList(wsiMaterialNumber);
            SpunlaceOutputDetailDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), SpunlaceOutputDetailDto.class);
            if (data != null) {
                // 仓库表
                ProductTraceabilityDto productTraceabilityList = wmsStockInfoMapper.getProductTraceabilityList(wsiMaterialNumber);
                if (productTraceabilityList != null) {
                    AjaxResult ajaxResult1 = feignService.selectCodingRulesById(productTraceabilityList.getWsiMaterialType());
                    MaterialCodingDto data1 = JSON.parseObject(JSON.toJSONString(ajaxResult1.get("data")), MaterialCodingDto.class);

                    // 公共物料表feign
                    PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, data.getMaterialCode()));
                    // 类别
                    productTraceabilityList.setWsiCategory(String.valueOf(publicGoods.getMaterialCategory()));
                    // 产品类别
                    productTraceabilityList.setWsiMaterialTypeDict(data1.getCodingRules());
                    // 产品编码
                    productTraceabilityList.setWsiMaterialCode(data.getMaterialCode());
                    // 产品名称
                    productTraceabilityList.setMaterialName(publicGoods.getMaterialName());
                    // 产品规格
                    productTraceabilityList.setMaterialSpec(publicGoods.getMaterialSpec());
                    productTraceabilityList.setWsiMaterialStatusDict(statusMap.get(productTraceabilityList.getWsiMaterialStatus()));
                    list.add(productTraceabilityList);

                }
                // 仓库日志表
                ProductTraceabilityDto productTraceabilityListLog = wmsStockInfoMapper.getProductTraceabilityListLog(wsiMaterialNumber);
                if (productTraceabilityListLog != null) {
                    AjaxResult ajaxResult2 = feignService.selectCodingRulesById(productTraceabilityListLog.getWsiMaterialType());
                    MaterialCodingDto data2 = JSON.parseObject(JSON.toJSONString(ajaxResult2.get("data")), MaterialCodingDto.class);

                    // 公共物料表feign
                    PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, data.getMaterialCode()));
                    // 类别
                    productTraceabilityListLog.setWsiCategory(String.valueOf(publicGoods.getMaterialCategory()));
                    // 产品类别
                    productTraceabilityListLog.setWsiMaterialTypeDict(data2.getCodingRules());
                    // 产品编码
                    productTraceabilityListLog.setWsiMaterialCode(data.getMaterialCode());
                    // 产品名称
                    productTraceabilityListLog.setMaterialName(publicGoods.getMaterialName());
                    // 产品规格
                    productTraceabilityListLog.setMaterialSpec(publicGoods.getMaterialSpec());
                    productTraceabilityListLog.setWsiMaterialStatusDict("已出库");
                    list.add(productTraceabilityListLog);
                } else {

                    // 公共物料表feign
                    PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, data.getMaterialCode()));

                    AjaxResult ajaxResult1 = feignService.selectCodingRulesById(String.valueOf(publicGoods.getMaterialType()));
                    MaterialCodingDto data1 = JSON.parseObject(JSON.toJSONString(ajaxResult1.get("data")), MaterialCodingDto.class);

                    ProductTraceabilityDto productTraceabilityDto = new ProductTraceabilityDto();
                    // 类别
                    productTraceabilityDto.setWsiCategory(String.valueOf(publicGoods.getMaterialCategory()));
                    // 产品类别
                    productTraceabilityDto.setWsiMaterialTypeDict(data1.getCodingRules());
                    // 产品编码
                    productTraceabilityDto.setWsiMaterialCode(data.getMaterialCode());
                    // 产品名称
                    productTraceabilityDto.setMaterialName(publicGoods.getMaterialName());
                    // 产品规格
                    productTraceabilityDto.setMaterialSpec(publicGoods.getMaterialSpec());
                    // 批次
                    productTraceabilityDto.setWsiMaterialBatch(data.getProductionBatch());
                    // 净重
                    productTraceabilityDto.setWsiNetWeight(data.getNetWeight());
                    // 幅宽
                    productTraceabilityDto.setWsiWidth(data.getNetWeight());
                    // 卷径
                    productTraceabilityDto.setWsiDiameter(Double.valueOf(data.getRollingDiameter()));
                    // 入库时间
                    productTraceabilityDto.setWsiReveiveTime(data.getStockDate());
                    // 关联单号
                    productTraceabilityDto.setWsiConnectNum(data.getSpunlaceOrderNumber());
                    // 入库状态
                    productTraceabilityDto.setWsiMaterialStatusDict(statusMap.get(data.getProductionStatus()));
                    list.add(productTraceabilityDto);
//                    for (ProductTraceabilityDto productTraceabilityDto1 : list) {
//                        productTraceabilityDto1.setWsiMaterialStatusDict(statusMap.get(productTraceabilityDto.getWsiMaterialStatus()));
//                    }
                }
            }
        }

        // 如果是小卷
        if (codingType.equals("3")) {

            AjaxResult ajaxResult1 = feignProductionService.getTraceabilityRollInfo(wsiMaterialNumber);
            RollPackingHistoryDto data1 = JSON.parseObject(JSON.toJSONString(ajaxResult1.get("data")), RollPackingHistoryDto.class);
            if (data1 != null && data1.getSmallVolumeNumber() != null) {


                // 小卷基础信息feign
                AjaxResult ajaxSmall = feignProductionService.selectBySmallVolumeNumber(wsiMaterialNumber);
                WmsSmallRollFoundationDto ajaxSmallData = JSON.parseObject(JSON.toJSONString(ajaxSmall.get("data")), WmsSmallRollFoundationDto.class);

                // 公共物料表feign
                PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, data1.getMaterialCode()));


                AjaxResult ajaxResult = feignService.selectCodingRulesById(String.valueOf(publicGoods.getMaterialType()));
                MaterialCodingDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), MaterialCodingDto.class);

                ProductTraceabilityDto productTraceabilityDto = new ProductTraceabilityDto();
                // 产品编码
                productTraceabilityDto.setWsiMaterialCode(data1.getMaterialCode());
                // 幅宽
                productTraceabilityDto.setWsiWidth(Double.valueOf(data1.getWidth()));
                // 产品类别
                productTraceabilityDto.setWsiMaterialType(String.valueOf(publicGoods.getMaterialType()));
                // 产品名称
                productTraceabilityDto.setMaterialName(publicGoods.getMaterialName());
                // 产品规格
                productTraceabilityDto.setMaterialSpec(publicGoods.getMaterialSpec());
                // 类别
                productTraceabilityDto.setWsiCategory(String.valueOf(publicGoods.getMaterialCategory()));
                // 产品类别
                productTraceabilityDto.setWsiMaterialTypeDict(data.getCodingRules());
                // 批次
                productTraceabilityDto.setWsiMaterialBatch(ajaxSmallData.getBatchNum());
                // 净重
                productTraceabilityDto.setWsiNetWeight(ajaxSmallData.getNetWeight());
                // 卷径
                productTraceabilityDto.setWsiDiameter(ajaxSmallData.getRollDiameter());
                // 物料等级
                productTraceabilityDto.setWsiMaterialGrade("1");
                // 库存状态
                productTraceabilityDto.setWsiMaterialStatus(ajaxSmallData.getStorageStatus());

                list.add(productTraceabilityDto);
            } else {
                AjaxResult ajaxResult = feignProductionService.selectRollPackingHistoryInfo(wsiMaterialNumber);
                RollPackingHistoryDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), RollPackingHistoryDto.class);
                if (data != null) {
                    // 小卷基础信息feign
                    AjaxResult ajaxSmall = feignProductionService.selectBySmallVolumeNumber(wsiMaterialNumber);
                    WmsSmallRollFoundationDto ajaxSmallData = JSON.parseObject(JSON.toJSONString(ajaxSmall.get("data")), WmsSmallRollFoundationDto.class);

                    PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, data.getMaterialCode()));

                    AjaxResult ajaxCoding = feignService.selectCodingRulesById(String.valueOf(publicGoods.getMaterialType()));
                    MaterialCodingDto codingData = JSON.parseObject(JSON.toJSONString(ajaxCoding.get("data")), MaterialCodingDto.class);

                    ProductTraceabilityDto productTraceabilityDto = new ProductTraceabilityDto();
                    // 产品编码
                    productTraceabilityDto.setWsiMaterialCode(data.getMaterialCode());
                    // 幅宽
                    productTraceabilityDto.setWsiWidth(Double.valueOf(data.getWidth()));
                    // 产品类别
                    productTraceabilityDto.setWsiMaterialType(String.valueOf(publicGoods.getMaterialType()));
                    // 产品名称
                    productTraceabilityDto.setMaterialName(publicGoods.getMaterialName());
                    // 产品规格
                    productTraceabilityDto.setMaterialSpec(publicGoods.getMaterialSpec());
                    // 类别
                    productTraceabilityDto.setWsiCategory(String.valueOf(publicGoods.getMaterialCategory()));
                    // 产品类别
                    productTraceabilityDto.setWsiMaterialTypeDict(codingData.getCodingRules());
                    // 批次
                    productTraceabilityDto.setWsiMaterialBatch(ajaxSmallData.getBatchNum());
                    // 净重
                    productTraceabilityDto.setWsiNetWeight(ajaxSmallData.getNetWeight());
                    // 卷径
                    productTraceabilityDto.setWsiDiameter(ajaxSmallData.getRollDiameter());
                    // 物料等级
                    productTraceabilityDto.setWsiMaterialGrade("1");
                    // 库存状态
                    productTraceabilityDto.setWsiMaterialStatus(ajaxSmallData.getStorageStatus());
                    list.add(productTraceabilityDto);
                }
            }
        }

        // 数据字典
        for (ProductTraceabilityDto productTraceabilityDto : list) {
            productTraceabilityDto.setWsiCategoryDict(qualityCategoryMap.get(productTraceabilityDto.getWsiCategory()));
            productTraceabilityDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(productTraceabilityDto.getWsiMaterialGrade()));
//            productTraceabilityDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(productTraceabilityDto.getWsiMaterialStatus()));
            productTraceabilityDto.setWsiFreezeInfoDict(freezeInfoMap.get(productTraceabilityDto.getWsiFreezeInfo()));
            productTraceabilityDto.setWsiMaterialStatusDict(weighingStatusMap.get(productTraceabilityDto.getWsiMaterialStatus()));
        }

        return list;
    }

    /**
     * 产品履历
     *
     * @param codingType
     * @param wsiMaterialNumber
     * @return
     */
    @Override
    public List<MaterialResumeDto> getProductPersonalDetails(String codingType, String wsiMaterialNumber) {

        List<MaterialResumeDto> list = new ArrayList<>();

        // 1、如果是成品
        if (codingType.equals("1")) {
            // 获取产品号码的物料编码
            ProductTraceabilityDto productTraceabilityList = wmsStockInfoMapper.getWsiMaterialNumberList(wsiMaterialNumber);
            if (productTraceabilityList != null) {
                if (productTraceabilityList.getWsiCategory().equals("4")) {

                    // 完工入库
                    List<MaterialResumeDto> wipCompletionInfoList = new ArrayList<>();
                    List<MaterialResumeDto> wipCompletionList = wmsStockInfoMapper.getWipCompletionList(wsiMaterialNumber);
                    for (MaterialResumeDto materialResumeDto : wipCompletionList) {
                        materialResumeDto.setJobTypeDict("扫码/批次入库");
                        materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                        wipCompletionInfoList.add(materialResumeDto);
                    }

                    // 销售退货
                    List<MaterialResumeDto> salesReturnList = new ArrayList<>();
                    List<MaterialResumeDto> salesReturnInfoList = wmsStockInfoMapper.getSalesReturnInfoList(wsiMaterialNumber);
                    for (MaterialResumeDto materialResumeDto : salesReturnInfoList) {
                        materialResumeDto.setJobTypeDict("扫码入库");
                        materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                        salesReturnList.add(materialResumeDto);
                    }

                    // 其他入库
                    List<MaterialResumeDto> otherWarehousingPersonalDetailsList = new ArrayList<>();
                    List<MaterialResumeDto> otherWarehousingPersonalDetails = wmsStockInfoMapper.getOtherWarehousingPersonalDetails(wsiMaterialNumber);
                    for (MaterialResumeDto materialResumeDto : otherWarehousingPersonalDetails) {
                        materialResumeDto.setJobTypeDict("扫码入库");
                        materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                        otherWarehousingPersonalDetailsList.add(materialResumeDto);
                    }

                    // 销售发货
                    List<MaterialResumeDto> salesShipmentList = new ArrayList<>();
                    List<MaterialResumeDto> salesShipmentInfoList = wmsStockInfoMapper.getSalesShipmentInfoList(wsiMaterialNumber);
                    for (MaterialResumeDto materialResumeDto : salesShipmentInfoList) {
                        materialResumeDto.setJobTypeDict("扫码/批次出库");
                        materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                        salesShipmentList.add(materialResumeDto);
                    }

                    // 返工出库
                    List<MaterialResumeDto> pickingCompleteList = new ArrayList<>();
                    List<MaterialResumeDto> pickingCompleteInfoList = wmsStockInfoMapper.getPickingCompleteInfoList(wsiMaterialNumber);
                    for (MaterialResumeDto materialResumeDto : pickingCompleteInfoList) {
                        materialResumeDto.setJobTypeDict("扫码/批次出库");
                        materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                        pickingCompleteList.add(materialResumeDto);
                    }

                    // 其他出库
                    List<MaterialResumeDto> otherOutboundList = new ArrayList<>();
                    List<MaterialResumeDto> otherOutbound = wmsStockInfoMapper.getOtherOutbound(wsiMaterialNumber);
                    for (MaterialResumeDto materialResumeDto : otherOutbound) {
                        materialResumeDto.setJobTypeDict("扫码/批次出库");
                        materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                        otherOutboundList.add(materialResumeDto);
                    }

                    // 成品称重
                    List<MaterialResumeDto> weighingFinishedList = new ArrayList<>();
                    AjaxResult weighingFinishedData = feignProductionService.getWeighingFinishedData(wsiMaterialNumber);
                    WeighingFinishedMaterialProductDto data = JSON.parseObject(JSON.toJSONString(weighingFinishedData.get("data")), WeighingFinishedMaterialProductDto.class);
                    if (data.getWarehousingBy() != null) {
                        MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                        materialResumeDto.setJobTypeDict("扫码入库");
                        materialResumeDto.setCreateUser(data.getWarehousingBy());
                        materialResumeDto.setCreateTime(data.getWarehousingTime());
                        weighingFinishedList.add(materialResumeDto);
                    }

                    // 扫描入库
                    List<MaterialResumeDto> spunlaceDetailList2 = new ArrayList<>();
                    AjaxResult spunlaceDetailList = feignProductionService.getSpunlaceDetail(wsiMaterialNumber);
                    SpunlaceOutputDetailDto dataList = JSON.parseObject(JSON.toJSONString(spunlaceDetailList.get("data")), SpunlaceOutputDetailDto.class);
                    if (dataList.getCreateMan() != null) {
                        MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                        materialResumeDto.setConnectDoc(dataList.getSpunlaceOrderNumber());
                        materialResumeDto.setCreateUser(dataList.getCreateMan());
                        materialResumeDto.setCreateTime(dataList.getCreateTime());
                        spunlaceDetailList2.add(materialResumeDto);
                    }

                    // 调拨单信息
                    List<MaterialResumeDto> allotManagementDetailInfoList = new ArrayList<>();
                    AllotManagementDetailDto allotManagementDetailInfo = allotManagementDetailMapper.getAllotManagementDetailInfo(wsiMaterialNumber);
                    if (allotManagementDetailInfo != null && allotManagementDetailInfo.getAllotDoc() != null) {
                        MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                        materialResumeDto.setJobTypeDict("调拨管理");
                        materialResumeDto.setDocumentType("调拨单信息");
                        materialResumeDto.setConnectDoc(allotManagementDetailInfo.getAllotDoc());
                        materialResumeDto.setCreateUser(allotManagementDetailInfo.getDepositorIn());
                        materialResumeDto.setCreateTime(allotManagementDetailInfo.getReviceTime());
                        allotManagementDetailInfoList.add(materialResumeDto);
                    }

                    // 盘点单信息
                    List<MaterialResumeDto> checkDetailList = new ArrayList<>();
                    List<CheckManagmentMaterialDto> checkManagmentMaterialInfo = checkManagementMaterialDetailMapper.getCheckManagmentMaterialInfo(wsiMaterialNumber);
                    for (CheckManagmentMaterialDto checkManagmentMaterialDto : checkManagmentMaterialInfo) {
                        if (checkManagmentMaterialDto.getCheckDoc() != null) {
                            MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                            materialResumeDto.setJobTypeDict("盘点管理");
                            materialResumeDto.setDocumentType("盘点单信息");
                            materialResumeDto.setConnectDoc(checkManagmentMaterialDto.getCheckDoc());
                            materialResumeDto.setCreateUser(checkManagmentMaterialDto.getCreateUser());
                            materialResumeDto.setCreateTime(checkManagmentMaterialDto.getCreateTime());
                            checkDetailList.add(materialResumeDto);
                        }
                    }

                    // 完工入库
                    list.addAll(wipCompletionInfoList);
                    // 销售退货
                    list.addAll(salesReturnList);
                    // 其他入库
                    list.addAll(otherWarehousingPersonalDetailsList);
                    // 销售发货
                    list.addAll(salesShipmentList);
                    // 返工出库
                    list.addAll(pickingCompleteList);
                    // 其他出库
                    list.addAll(otherOutboundList);
                    // 成品称重
                    list.addAll(weighingFinishedList);
                    // 扫描入库
                    list.addAll(spunlaceDetailList2);
                    // 调拨单信息
                    list.addAll(allotManagementDetailInfoList);
                    // 盘点单信息
                    list.addAll(checkDetailList);
                }
            }
        }
        // 2、如果是母卷
        if (codingType.equals("2")) {
            AjaxResult cutOrdersDocumentInfo = feignProductionService.getCutOrdersDocumentInfo(wsiMaterialNumber);
            CutOrdersDocumentDetailDto data = JSON.parseObject(JSON.toJSONString(cutOrdersDocumentInfo.get("data")), CutOrdersDocumentDetailDto.class);
            if (data != null) {
                // 完工入库
                List<MaterialResumeDto> wipCompletionInfoList = new ArrayList<>();
                List<MaterialResumeDto> wipCompletionList = wmsStockInfoMapper.getWipCompletionList(wsiMaterialNumber);
                for (MaterialResumeDto materialResumeDto : wipCompletionList) {
                    materialResumeDto.setJobTypeDict("扫码/批次入库");
                    materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                    wipCompletionInfoList.add(materialResumeDto);
                }

                // 其他入库
                List<MaterialResumeDto> otherWarehousingPersonalDetailsList = new ArrayList<>();
                List<MaterialResumeDto> otherWarehousingPersonalDetails = wmsStockInfoMapper.getOtherWarehousingPersonalDetails(wsiMaterialNumber);
                for (MaterialResumeDto materialResumeDto : otherWarehousingPersonalDetails) {
                    materialResumeDto.setJobTypeDict("扫码入库");
                    materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                    otherWarehousingPersonalDetailsList.add(materialResumeDto);
                }

                // 生产领料
                List<MaterialResumeDto> pickingPersonalDetailsList = new ArrayList<>();
                List<MaterialResumeDto> pickingPersonalDetails = wmsStockInfoMapper.getPickingPersonalDetails(wsiMaterialNumber);
                for (MaterialResumeDto materialResumeDto : pickingPersonalDetails) {
                    materialResumeDto.setJobTypeDict("扫码/批次出库");
                    materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                    pickingPersonalDetailsList.add(materialResumeDto);
                }
                // 返工出库
                List<MaterialResumeDto> pickingCompleteList = new ArrayList<>();
                List<MaterialResumeDto> pickingCompleteInfoList = wmsStockInfoMapper.getPickingCompleteInfoList(wsiMaterialNumber);
                for (MaterialResumeDto materialResumeDto : pickingCompleteInfoList) {
                    materialResumeDto.setJobTypeDict("扫码/批次出库");
                    materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                    pickingCompleteList.add(materialResumeDto);
                }

                // 其他出库
                List<MaterialResumeDto> otherOutboundList = new ArrayList<>();
                List<MaterialResumeDto> otherOutbound = wmsStockInfoMapper.getOtherOutbound(wsiMaterialNumber);
                for (MaterialResumeDto materialResumeDto : otherOutbound) {
                    materialResumeDto.setJobTypeDict("扫码/批次出库");
                    materialResumeDto.setDocumentType(DocumentTypeEnum.getValue(Integer.parseInt(materialResumeDto.getDocumentType())));
                    otherOutboundList.add(materialResumeDto);
                }

                // 水刺制令单 产出打印
                List<MaterialResumeDto> spunlaceDetailList1 = new ArrayList<>();
                AjaxResult spunlaceDetail = feignProductionService.getSpunlaceDetail(wsiMaterialNumber);
                SpunlaceOutputDetailDto data1 = JSON.parseObject(JSON.toJSONString(spunlaceDetail.get("data")), SpunlaceOutputDetailDto.class);
                if (data1.getCreateMan() != null) {
                    MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                    materialResumeDto.setJobTypeDict("产出打印");
                    materialResumeDto.setDocumentType("水刺制令单");
                    materialResumeDto.setConnectDoc(data1.getSpunlaceOrderNumber());
                    materialResumeDto.setCreateUser(data1.getCreateMan());
                    materialResumeDto.setCreateTime(data1.getCreateTime());
                    spunlaceDetailList1.add(materialResumeDto);
                }

                // 水刺制令单 扫描入库
                List<MaterialResumeDto> spunlaceDetailList2 = new ArrayList<>();
                AjaxResult spunlaceDetailList = feignProductionService.getSpunlaceDetail(wsiMaterialNumber);
                SpunlaceOutputDetailDto dataList = JSON.parseObject(JSON.toJSONString(spunlaceDetailList.get("data")), SpunlaceOutputDetailDto.class);
                if (dataList.getCreateMan() != null && dataList.getProductionStatus().equals("2")) {
                    MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                    materialResumeDto.setJobTypeDict("扫描入库");
                    materialResumeDto.setDocumentType("水刺制令单");
                    materialResumeDto.setConnectDoc(dataList.getSpunlaceOrderNumber());
                    materialResumeDto.setCreateUser(dataList.getCreateMan());
                    materialResumeDto.setCreateTime(dataList.getCreateTime());
                    spunlaceDetailList2.add(materialResumeDto);
                }

                // 验布
                List<MaterialResumeDto> ClothInspectionDetailList = new ArrayList<>();
                AjaxResult list1 = feignProductionService.selectDetailLisMasterVolumeNumber(wsiMaterialNumber);
                List<ClothInspectionDetailDto> data2 = JSON.parseArray(JSON.toJSONString(list1.get("data")), ClothInspectionDetailDto.class);
                for (ClothInspectionDetailDto clothInspectionDetailDto : data2) {
                    MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                    materialResumeDto.setJobTypeDict("验布");
                    materialResumeDto.setCreateUser(clothInspectionDetailDto.getClothInspectionBy());
                    materialResumeDto.setCreateTime(clothInspectionDetailDto.getClothInspectionTime());
                    ClothInspectionDetailList.add(materialResumeDto);
                }

                // 分切
                List<MaterialResumeDto> CutOrdersDocumentList = new ArrayList<>();
                AjaxResult CutOrdersList = feignProductionService.getCutOrdersDocumentInfo(wsiMaterialNumber);
                CutOrdersDocumentDetailDto data3 = JSON.parseObject(JSON.toJSONString(CutOrdersList.get("data")), CutOrdersDocumentDetailDto.class);
                if (data3.getSlittBy() != null && data3.getSlittingStatus().equals("2")) {
                    MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                    materialResumeDto.setJobTypeDict("分切");
                    materialResumeDto.setDocumentType("分切制令单");
                    materialResumeDto.setConnectDoc(data3.getDocumentNum());
                    materialResumeDto.setCreateUser(data3.getSlittBy());
                    materialResumeDto.setCreateTime(data3.getSlittTime());
                    CutOrdersDocumentList.add(materialResumeDto);
                }

                // 分卷

                list.addAll(wipCompletionInfoList);
                list.addAll(otherWarehousingPersonalDetailsList);
                list.addAll(pickingPersonalDetailsList);
                list.addAll(pickingCompleteList);
                list.addAll(otherOutboundList);
                list.addAll(spunlaceDetailList1);
                list.addAll(spunlaceDetailList2);
                list.addAll(ClothInspectionDetailList);
                list.addAll(CutOrdersDocumentList);

            }
        }


        //3、如果是小卷
        if (codingType.equals("3")) {
            // 小卷打包
            AjaxResult ajaxResult = feignProductionService.selectRollPackingHistoryInfo(wsiMaterialNumber);
            RollPackingHistoryDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), RollPackingHistoryDto.class);
            if (data != null && data.getCreateTime() != null) {
                MaterialResumeDto materialResumeDto = new MaterialResumeDto();
                materialResumeDto.setJobTypeDict("小卷打包");
                materialResumeDto.setCreateUser(data.getFeeder());
                materialResumeDto.setCreateTime(data.getCreateTime());
                list.add(materialResumeDto);
            }
        }

        return list;
    }

    /**
     * 库存汇总
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    public List<InventorySummaryDto> getInventorySummaryList(WmsStockInfoVo wmsStockInfoVo) {

        // 判断仓库模糊查询的所属层级id
        if (null != wmsStockInfoVo.getWarehouseIds()) {
            WarehouseDto warehouseCode = warehouseMapper.getWarehouseCode(wmsStockInfoVo.getWarehouseIds());
            if (warehouseCode.getWarehouseType().equals("1")) {
                wmsStockInfoVo.setWsiWarehourse(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("2")) {
                wmsStockInfoVo.setWsiReservoirArea(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("3")) {
                wmsStockInfoVo.setWsiStorageLoaction(wmsStockInfoVo.getWarehouseIds());
            }
        }

        // 类别
        List<SysDictData> qualityCategory = DictUtils.getDictCache("quality_category");
        Map<String, String> qualityCategoryMap = qualityCategory.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        startPage();
        List<InventorySummaryDto> list = wmsStockInfoMapper.getInventorySummaryList(wmsStockInfoVo);
        // 获取类别名称
        for (InventorySummaryDto inventorySummaryDto : list) {
            AjaxResult ajaxResult = feignService.selectCodingRulesById(inventorySummaryDto.getMaterialType());
            MaterialCodingDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), MaterialCodingDto.class);
            inventorySummaryDto.setMaterialTypeDict(data.getCodingRules());

            // 类别字典
            inventorySummaryDto.setWsiCategoryDict(qualityCategoryMap.get(inventorySummaryDto.getWsiCategory()));
        }
        return list;
    }

    /**
     * 原料明细
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    public List<DetailsMaterialsDto> getInventoryMaterialDetailed(WmsStockInfoVo wmsStockInfoVo) {
        // 判断仓库模糊查询的所属层级id
        if (null != wmsStockInfoVo.getWarehouseIds()) {
            WarehouseDto warehouseCode = warehouseMapper.getWarehouseCode(wmsStockInfoVo.getWarehouseIds());
            if (warehouseCode.getWarehouseType().equals("1")) {
                wmsStockInfoVo.setWsiWarehourse(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("2")) {
                wmsStockInfoVo.setWsiReservoirArea(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("3")) {
                wmsStockInfoVo.setWsiStorageLoaction(wmsStockInfoVo.getWarehouseIds());
            }
        }

        // 库存状态
        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 物料等级
        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        startPage();
        List<DetailsMaterialsDto> list = wmsStockInfoMapper.getInventoryMaterialDetailed(wmsStockInfoVo);
        for (DetailsMaterialsDto detailsMaterialsDto : list) {
            AjaxResult ajaxResult = feignService.selectCodingRulesById(String.valueOf(detailsMaterialsDto.getWsiMaterialType()));
            MaterialCodingDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), MaterialCodingDto.class);

            // 库存状态
            detailsMaterialsDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(detailsMaterialsDto.getWsiMaterialStatus()));
            // 物料等级
            detailsMaterialsDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(detailsMaterialsDto.getWsiMaterialGrade()));
            detailsMaterialsDto.setMaterialTypeDict(data.getCodingRules());
        }
        return list;
    }

    /**
     * 辅料明细
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    public List<DetailsMaterialsDto> getInventoryAccessoriesDetailed(WmsStockInfoVo wmsStockInfoVo) {

        // 判断仓库模糊查询的所属层级id
        if (null != wmsStockInfoVo.getWarehouseIds()) {
            WarehouseDto warehouseCode = warehouseMapper.getWarehouseCode(wmsStockInfoVo.getWarehouseIds());
            if (warehouseCode.getWarehouseType().equals("1")) {
                wmsStockInfoVo.setWsiWarehourse(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("2")) {
                wmsStockInfoVo.setWsiReservoirArea(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("3")) {
                wmsStockInfoVo.setWsiStorageLoaction(wmsStockInfoVo.getWarehouseIds());
            }
        }
        // 库存状态
        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 物料等级
        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        startPage();
        List<DetailsMaterialsDto> inventoryAccessoriesDetailed = wmsStockInfoMapper.getInventoryAccessoriesDetailed(wmsStockInfoVo);
        for (DetailsMaterialsDto detailsMaterialsDto : inventoryAccessoriesDetailed) {
            AjaxResult ajaxResult = feignService.selectCodingRulesById(String.valueOf(detailsMaterialsDto.getWsiMaterialType()));
            MaterialCodingDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), MaterialCodingDto.class);

            // 库存状态
            detailsMaterialsDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(detailsMaterialsDto.getWsiMaterialStatus()));
            // 物料等级
            detailsMaterialsDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(detailsMaterialsDto.getWsiMaterialGrade()));
            detailsMaterialsDto.setMaterialTypeDict(data.getCodingRules());
        }
        return inventoryAccessoriesDetailed;
    }

    /**
     * 成品明细
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    public List<DetailsMaterialsDto> getInventoryFinishProductDetailed(WmsStockInfoVo wmsStockInfoVo) {

        // 判断仓库模糊查询的所属层级id
        if (null != wmsStockInfoVo.getWarehouseIds()) {
            WarehouseDto warehouseCode = warehouseMapper.getWarehouseCode(wmsStockInfoVo.getWarehouseIds());
            if (warehouseCode.getWarehouseType().equals("1")) {
                wmsStockInfoVo.setWsiWarehourse(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("2")) {
                wmsStockInfoVo.setWsiReservoirArea(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("3")) {
                wmsStockInfoVo.setWsiStorageLoaction(wmsStockInfoVo.getWarehouseIds());
            }
        }

        // 库存状态
        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 物料等级
        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 生产阶别
        List<SysDictData> qualityProductionLevelStatus = DictUtils.getDictCache("quality_production_level");
        Map<String, String> qualityProductionLevelStatusMap = qualityProductionLevelStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        startPage();
        List<DetailsMaterialsDto> inventoryFinishProductDetailed = wmsStockInfoMapper.getInventoryFinishProductDetailed(wmsStockInfoVo);
        for (DetailsMaterialsDto detailsMaterialsDto : inventoryFinishProductDetailed) {
            AjaxResult ajaxResult = feignService.selectCodingRulesById(String.valueOf(detailsMaterialsDto.getWsiMaterialType()));
            MaterialCodingDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), MaterialCodingDto.class);

            // 库存状态
            detailsMaterialsDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(detailsMaterialsDto.getWsiMaterialStatus()));
            // 物料等级
            detailsMaterialsDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(detailsMaterialsDto.getWsiMaterialGrade()));
            // 生产阶别
            detailsMaterialsDto.setWsiProducedStepDict(qualityProductionLevelStatusMap.get(detailsMaterialsDto.getWsiProducedStep()));
            detailsMaterialsDto.setMaterialTypeDict(data.getCodingRules());
        }
        return inventoryFinishProductDetailed;
    }

    /**
     * 半成品明细
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    public List<DetailsMaterialsDto> getInventoryMaterialHalfDetailed(WmsStockInfoVo wmsStockInfoVo) {

        // 判断仓库模糊查询的所属层级id
        if (null != wmsStockInfoVo.getWarehouseIds()) {
            WarehouseDto warehouseCode = warehouseMapper.getWarehouseCode(wmsStockInfoVo.getWarehouseIds());
            if (warehouseCode.getWarehouseType().equals("1")) {
                wmsStockInfoVo.setWsiWarehourse(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("2")) {
                wmsStockInfoVo.setWsiReservoirArea(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("3")) {
                wmsStockInfoVo.setWsiStorageLoaction(wmsStockInfoVo.getWarehouseIds());
            }
        }
        // 库存状态
        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 物料等级
        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 生产阶别
        List<SysDictData> qualityProductionLevelStatus = DictUtils.getDictCache("quality_production_level");
        Map<String, String> qualityProductionLevelStatusMap = qualityProductionLevelStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        startPage();
        List<DetailsMaterialsDto> inventoryMaterialHalfDetailed = wmsStockInfoMapper.getInventoryMaterialHalfDetailed(wmsStockInfoVo);

        for (DetailsMaterialsDto detailsMaterialsDto : inventoryMaterialHalfDetailed) {
            AjaxResult ajaxResult = feignService.selectCodingRulesById(String.valueOf(detailsMaterialsDto.getWsiMaterialType()));
            MaterialCodingDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), MaterialCodingDto.class);

            // 库存状态
            detailsMaterialsDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(detailsMaterialsDto.getWsiMaterialStatus()));
            // 物料等级
            detailsMaterialsDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(detailsMaterialsDto.getWsiMaterialGrade()));
            // 生产阶别
            detailsMaterialsDto.setWsiProducedStepDict(qualityProductionLevelStatusMap.get(detailsMaterialsDto.getWsiProducedStep()));
            detailsMaterialsDto.setMaterialTypeDict(data.getCodingRules());
        }

        return inventoryMaterialHalfDetailed;
    }

    /**
     * 废料明细
     *
     * @param wmsStockInfoVo
     * @return
     */
    @Override
    public List<DetailsMaterialsDto> getInventoryWasteDetailed(WmsStockInfoVo wmsStockInfoVo) {
        // 判断仓库模糊查询的所属层级id
        if (null != wmsStockInfoVo.getWarehouseIds()) {
            WarehouseDto warehouseCode = warehouseMapper.getWarehouseCode(wmsStockInfoVo.getWarehouseIds());
            if (warehouseCode.getWarehouseType().equals("1")) {
                wmsStockInfoVo.setWsiWarehourse(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("2")) {
                wmsStockInfoVo.setWsiReservoirArea(wmsStockInfoVo.getWarehouseIds());
            }
            if (warehouseCode.getWarehouseType().equals("3")) {
                wmsStockInfoVo.setWsiStorageLoaction(wmsStockInfoVo.getWarehouseIds());
            }
        }
        // 库存状态
        List<SysDictData> qualityInventoryRecheckStatus = DictUtils.getDictCache("wms_stock_info_status");
        Map<String, String> qualityInventoryRecheckStatusMap = qualityInventoryRecheckStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 物料等级
        List<SysDictData> stockInfoGrade = DictUtils.getDictCache("wms_stock_info_grade");
        Map<String, String> stockInfoGradeMap = stockInfoGrade.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));

        // 生产阶别
        List<SysDictData> qualityProductionLevelStatus = DictUtils.getDictCache("quality_production_level");
        Map<String, String> qualityProductionLevelStatusMap = qualityProductionLevelStatus.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
        startPage();
        List<DetailsMaterialsDto> inventoryWasteDetailed = wmsStockInfoMapper.getInventoryWasteDetailed(wmsStockInfoVo);

        for (DetailsMaterialsDto detailsMaterialsDto : inventoryWasteDetailed) {

            AjaxResult ajaxResult = feignService.selectCodingRulesById(String.valueOf(detailsMaterialsDto.getWsiMaterialType()));
            MaterialCodingDto data = JSON.parseObject(JSON.toJSONString(ajaxResult.get("data")), MaterialCodingDto.class);

            // 库存状态
            detailsMaterialsDto.setWsiMaterialStatusDict(qualityInventoryRecheckStatusMap.get(detailsMaterialsDto.getWsiMaterialStatus()));
            // 物料等级
            detailsMaterialsDto.setWsiMaterialGradeDict(stockInfoGradeMap.get(detailsMaterialsDto.getWsiMaterialGrade()));
            // 生产阶别
            detailsMaterialsDto.setWsiProducedStepDict(qualityProductionLevelStatusMap.get(detailsMaterialsDto.getWsiProducedStep()));
            detailsMaterialsDto.setMaterialTypeDict(data.getCodingRules());
        }

        return inventoryWasteDetailed;
    }

    /**
     * 委外发货新增物料汇总信息
     *
     * @param outsourceSumVo
     * @return
     */
    @Override
    public List<OutsourceSumDto> outsourceSum(OutsourceSumVo outsourceSumVo) {
        List<OutsourceSumDto> list = wmsStockInfoMapper.getOutsourceStock(outsourceSumVo);
        for (OutsourceSumDto outsourceSumDto : list) {
            //根据字典查出单位
            List<SysDictData> unitList = DictUtils.getDictCache("sys_material_unit");
            Map<String, String> unitMap = unitList.stream().collect(Collectors.toMap(SysDictData::getDictValue, SysDictData::getDictLabel));
            outsourceSumDto.setMaterialUnitDict(unitMap.get(outsourceSumDto.getMaterialUnitDict()));
        }
        return list;
    }

    /**
     * 根据母卷号码删除仓库数据（fegin调用）
     *
     * @param masterVolumeNum
     */
    @Override
    public void deleteByMasterVolumeNum(String masterVolumeNum) {
        WmsStockInfo wmsStockInfo = wmsStockInfoMapper.selectOne(new QueryWrapper<WmsStockInfo>().lambda().eq(WmsStockInfo::getWsiMaterialNumber, masterVolumeNum));
        wmsStockInfoMapper.deleteById(wmsStockInfo);
    }

    /**
     * 根据母卷号码查询母卷
     *
     * @param wsiMaterialNumber
     * @return
     */
    @Override
    public OutboundLog selectProductStockInfoById(String wsiMaterialNumber) {
        return outboundLogMapper.selectOne(new QueryWrapper<OutboundLog>().lambda().eq(OutboundLog::getWsiMaterialNumber, wsiMaterialNumber));
    }

    /**
     * 品质处理修改对应物料等级
     *
     * @param updateGradeVo
     * @return
     */
    @Override
    public boolean updateMaterialGrade(UpdateGradeVo updateGradeVo) {
        List<String> materialNumberList = updateGradeVo.getMaterialNumberList();
        int materialLevel = updateGradeVo.getMaterialLevel();
        List<WmsStockInfo> wmsStockInfos = wmsStockInfoMapper.selectList(new QueryWrapper<WmsStockInfo>().lambda().in(WmsStockInfo::getWsiMaterialNumber, materialNumberList));

        for (WmsStockInfo entity : wmsStockInfos) {
            entity.setWsiMaterialGrade(String.valueOf(materialLevel));
        }
        return updateBatchById(wmsStockInfos);
    }

    /**
     * 消息提醒-最小安全库存
     */
    @Override
    public void maxStock() throws Exception {
        //分组查出仓库的物料编码,重量
        List<WmsStockInfoSumDto> materialCodeList = wmsStockInfoMapper.groupMaterialCode();

        ArrayList<SysWorkbenchMessageVo> workMessageList = new ArrayList<>();

        List<MessageRemindDto> messageRemindDtoList = new ArrayList<>();

        //查询消息提醒表
        List<SysWorkbenchMessage> infoList = feignService.getInfo("1");

        for (WmsStockInfoSumDto wmsStockInfoSumDto : materialCodeList) {
            //查询这个物料编码在公共物料表中的最小安全库存
            PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, wmsStockInfoSumDto.getWsiMaterialCode()));

            //通过物料编码查询出告警信息
            SysTheAlarmDto alarm = feignService.getAlarm(wmsStockInfoSumDto.getWsiMaterialCode(), "1");

            if (alarm != null) {

                //如果库存重量小余最小安全库存，则提醒
                if (wmsStockInfoSumDto.getStockNum() < publicGoods.getMaterialMinSecurity()) {


                    MessageRemindDto messageRemindDto = new MessageRemindDto();

                    String message = "物料编码:" + wmsStockInfoSumDto.getWsiMaterialCode() + "物料名称:" + wmsStockInfoSumDto.getWsiMaterialName() + "库存不足请及时处理";

                    //获取关结方式
                    String alarmNexus = alarm.getAlarmNexus();

                    boolean flag = false;

                    if ("1".equals(alarmNexus)) {
                        for (SysWorkbenchMessage sysWorkbenchMessage : infoList) {
                            if (message.equals(sysWorkbenchMessage.getMessageContent()) && (wmsStockInfoSumDto.getStockNum() + "").equals(sysWorkbenchMessage.getStock() + "")) {
                                flag = true;
                                break;
                            }
                        }
                    }

                    if (flag) {
                        continue;
                    }

                    messageRemindDto.setModelType(1);
                    messageRemindDto.setMessage(message);

                    //添加告警信息
                    messageRemindDto.setAlarmWay(alarm.getAlarmWay());
                    messageRemindDto.setAlarmFrequency(alarm.getAlarmFrequency());
                    messageRemindDto.setAlarmUnit(alarm.getAlarmUnit());
                    messageRemindDto.setAlarmNexus(alarm.getAlarmNexus());
                    messageRemindDto.setUserIds(alarm.getAlarmRoleId());
                    messageRemindDto.setMessageType(1);
                    messageRemindDto.setMessageTypeDict("库存告警");

                    SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                    messageRemindDto.setToday(simpleDateFormat.format(new Date()));

                    messageRemindDto.setStock(String.valueOf(wmsStockInfoSumDto.getStockNum()));

                    messageRemindDtoList.add(messageRemindDto);


                    SysWorkbenchMessageVo sysWorkbenchMessageVo = new SysWorkbenchMessageVo();
                    sysWorkbenchMessageVo.setMessageType(1);//库存告警
                    sysWorkbenchMessageVo.setMessageContent(message);
                    sysWorkbenchMessageVo.setWarnTime(new Date());
                    sysWorkbenchMessageVo.setReadMark(2);
                    //sysWorkbenchMessageVo.setUserId();
                    workMessageList.add(sysWorkbenchMessageVo);

                }

            }
        }
        if (messageRemindDtoList.size() != 0) {
            MessageRemindMqUtil.messageRemind(messageRemindDtoList);
        }

        if (workMessageList.size() != 0) {
            //feignService.insertWork(workMessageList);
        }
    }

    /**
     * 消息提醒-保质期告警
     */
    @Override
    public void expirationDate() throws Exception {
        //分组查出仓库的物料编码,重量
        List<WmsStockInfoSumDto> materialCodeList = wmsStockInfoMapper.groupMaterialCode();

        //保质期
        Map<String, Integer> expirationMap = new HashMap<>();

        //过期提醒
        Map<String, Integer> reminderMap = new HashMap<>();

        //告警信息
        Map<String, Object> alarmMap = new HashMap<>();

        //查询消息提醒表
        List<SysWorkbenchMessage> infoList = feignService.getInfo("2");

        for (WmsStockInfoSumDto wmsStockInfoSumDto : materialCodeList) {

            //如果未配置消息提醒则不提醒


            //通过物料编码查出保质期和过期提醒
            PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, wmsStockInfoSumDto.getWsiMaterialCode()));

            //保质期
            expirationMap.put(wmsStockInfoSumDto.getWsiMaterialCode(), publicGoods.getMaterialQuality());
            //过期提醒
            reminderMap.put(wmsStockInfoSumDto.getWsiMaterialCode(), publicGoods.getMaterialOverdue());

            //通过物料编码查询出告警信息
            SysTheAlarmDto alarm = feignService.getAlarm(wmsStockInfoSumDto.getWsiMaterialCode(), "2");

            alarmMap.put(wmsStockInfoSumDto.getWsiMaterialCode(), alarm);

        }

        //查询库存中的所有物料号码
        List<WmsStockDto> materialNumberList = wmsStockInfoMapper.getMaterialList();

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");

        List<MessageRemindDto> messageRemindDtoList = new ArrayList<>();

        for (WmsStockDto wmsStockInfo : materialNumberList) {
            //生产日期
            Date wsiProducedDate = wmsStockInfo.getWsiProducedDate();

            //如果生产日期不为null
            SysTheAlarmDto alarm = (SysTheAlarmDto) alarmMap.get(wmsStockInfo.getWsiMaterialCode());

            if (alarm != null) {

                if (wsiProducedDate != null) {

                    String format = simpleDateFormat.format(wsiProducedDate);
                    Date date = new Date();
                    String format1 = simpleDateFormat.format(date);


                    int daysBetween = DateUtilss.daysBetween(simpleDateFormat.format(wsiProducedDate), simpleDateFormat.format(new Date()));

                    //如果保质期-复检天数<=当前时间-生产日期
                    String wsiMaterialCode = wmsStockInfo.getWsiMaterialCode();
                    Integer integer = expirationMap.get(wsiMaterialCode);

                    Integer integer1 = reminderMap.get(wmsStockInfo.getWsiMaterialCode());
                    if (expirationMap.get(wmsStockInfo.getWsiMaterialCode()) >= daysBetween) {
                        if (expirationMap.get(wmsStockInfo.getWsiMaterialCode()) - reminderMap.get(wmsStockInfo.getWsiMaterialCode()) <= daysBetween) {
                            //获取过期天数
                            int exceedTime = expirationMap.get(wmsStockInfo.getWsiMaterialCode()) - daysBetween;

                            //消息
                            String message = "物料号码:" + wmsStockInfo.getWsiMaterialNumber() + ",物料名称:" + wmsStockInfo.getMaterialName() + "将在" + exceedTime + "天后超期,请及时处理";

                            //获取关结方式
                            String alarmNexus = alarm.getAlarmNexus();

                            boolean flag = false;

                            if ("1".equals(alarmNexus)) {
                                for (SysWorkbenchMessage sysWorkbenchMessage : infoList) {
                                    if (message.equals(sysWorkbenchMessage.getMessageContent())) {
                                        flag = true;
                                        break;
                                    }
                                }
                            }

                            if (flag) {
                                continue;
                            }


                            MessageRemindDto messageRemindDto = new MessageRemindDto();

                            messageRemindDto.setMessage(message);
                            messageRemindDto.setModelType(1);


                            messageRemindDto.setAlarmWay(alarm.getAlarmWay());
                            messageRemindDto.setAlarmFrequency(alarm.getAlarmFrequency());
                            messageRemindDto.setAlarmUnit(alarm.getAlarmUnit());
                            messageRemindDto.setAlarmNexus(alarm.getAlarmNexus());
                            messageRemindDto.setUserIds(alarm.getAlarmRoleId());
                            messageRemindDto.setMessageType(2);

                            messageRemindDto.setMessageTypeDict("保质期告警");

                            SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                            messageRemindDto.setToday(simpleDateFormat1.format(new Date()));

                            messageRemindDtoList.add(messageRemindDto);
                            //触发提醒，内容为“XX号码、XX名称将在X天后超期，请及时处理”


                        }
                    } else {
                        //消息
                        String message = "物料号码:" + wmsStockInfo.getWsiMaterialNumber() + ",物料名称:" + wmsStockInfo.getMaterialName() + "已超期,请及时处理";

                        //获取关结方式
                        String alarmNexus = alarm.getAlarmNexus();

                        boolean flag = false;

                        if ("1".equals(alarmNexus)) {
                            for (SysWorkbenchMessage sysWorkbenchMessage : infoList) {
                                if (message.equals(sysWorkbenchMessage.getMessageContent())) {
                                    flag = true;
                                    break;
                                }
                            }
                        }

                        if (flag) {
                            continue;
                        }

                        MessageRemindDto messageRemindDto = new MessageRemindDto();

                        messageRemindDto.setMessage(message);
                        messageRemindDto.setModelType(1);

                        messageRemindDto.setAlarmWay(alarm.getAlarmWay());
                        messageRemindDto.setAlarmFrequency(alarm.getAlarmFrequency());
                        messageRemindDto.setAlarmUnit(alarm.getAlarmUnit());
                        messageRemindDto.setAlarmNexus(alarm.getAlarmNexus());
                        messageRemindDto.setUserIds(alarm.getAlarmRoleId());
                        messageRemindDto.setMessageType(2);

                        messageRemindDto.setMessageTypeDict("保质期告警");

                        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                        messageRemindDto.setToday(simpleDateFormat1.format(new Date()));

                        //“XX号码、XX名称已超期，请及时处理”
                        messageRemindDtoList.add(messageRemindDto);

                    }
                }
            }
        }
        if (messageRemindDtoList.size() != 0) {
            MessageRemindMqUtil.messageRemind(messageRemindDtoList);
        }
    }

    /**
     * 复检到期提醒
     *
     * @throws Exception
     */
    @Override
    public void recheck() throws Exception {
        //分组查出仓库的物料编码,重量
        List<WmsStockInfoSumDto> materialCodeList = wmsStockInfoMapper.groupMaterialCode();

        //复检日期
        HashMap<String, Integer> inspectionMap = new HashMap<>();

        //复检提醒
        HashMap<String, Integer> reminderMap = new HashMap<>();

        //告警信息
        Map<String, Object> alarmMap = new HashMap<>();

        //批量消息集合
        List<MessageRemindDto> messageRemindDtoList = new ArrayList<>();

        //查询消息提醒表
        List<SysWorkbenchMessage> infoList = feignService.getInfo("3");

        //定义集合修改物料号码集合
        List<UpdateWmsVo> updateWmsVos = new ArrayList<>();

        for (WmsStockInfoSumDto wmsStockInfoSumDto : materialCodeList) {

            //通过物料编码查出复检日期和复检提醒
            PublicGoods publicGoods = publicGoodsMapper.selectOne(new QueryWrapper<PublicGoods>().lambda().eq(PublicGoods::getMaterialCode, wmsStockInfoSumDto.getWsiMaterialCode()));

            //复检日期
            inspectionMap.put(wmsStockInfoSumDto.getWsiMaterialCode(), publicGoods.getMaterialInspection());
            //复检提醒
            reminderMap.put(wmsStockInfoSumDto.getWsiMaterialCode(), publicGoods.getMaterialReminder());

            //通过物料编码查询出告警信息
            SysTheAlarmDto alarm = feignService.getAlarm(wmsStockInfoSumDto.getWsiMaterialCode(), "3");

            alarmMap.put(wmsStockInfoSumDto.getWsiMaterialCode(), alarm);

        }

        //查询库存中的所有物料号码
        List<WmsStockDto> materialNumberList = wmsStockInfoMapper.getMaterialList();

        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/dd");

        for (WmsStockDto wmsStockInfo : materialNumberList) {

            if (wmsStockInfo.getWsiMaterialNumber().equals("DC23060705-0268")) {
                System.out.println("111");
            }

            //入库日期
            Date wsiProducedDate = wmsStockInfo.getWsiReveiveTime();

            SysTheAlarmDto alarm = (SysTheAlarmDto) alarmMap.get(wmsStockInfo.getWsiMaterialCode());

            if (alarm != null) {

                if (wsiProducedDate != null) {

                    if (wmsStockInfo.getWsiRecheckDate() != null) {
                        wsiProducedDate = wmsStockInfo.getWsiRecheckDate();
                    }

                    int daysBetween = DateUtilss.daysBetween(simpleDateFormat.format(wsiProducedDate), simpleDateFormat.format(new Date()));


                    //如果复检日期-复检天数<=当前时间-生产日期
                    if (inspectionMap.get(wmsStockInfo.getWsiMaterialCode()) >= daysBetween) {

                        if (inspectionMap.get(wmsStockInfo.getWsiMaterialCode()) - daysBetween <= reminderMap.get(wmsStockInfo.getWsiMaterialCode())) {

                            //获取过期天数
                            int exceedTime = inspectionMap.get(wmsStockInfo.getWsiMaterialCode()) - daysBetween;

                            //消息
                            String message = "物料号码:" + wmsStockInfo.getWsiMaterialNumber() + ",物料名称:" + wmsStockInfo.getMaterialName() + "将在" + exceedTime + "天后超期复检,请及时处理";

                            //获取关结方式
                            String alarmNexus = alarm.getAlarmNexus();

                            boolean flag = false;

                            if ("1".equals(alarmNexus)) {
                                for (SysWorkbenchMessage sysWorkbenchMessage : infoList) {
                                    if (message.equals(sysWorkbenchMessage.getMessageContent())) {
                                        flag = true;
                                        break;
                                    }
                                }
                            }

                            if (flag) {
                                continue;
                            }


                            MessageRemindDto messageRemindDto = new MessageRemindDto();

                            messageRemindDto.setMessage(message);
                            messageRemindDto.setModelType(1);


                            messageRemindDto.setAlarmWay(alarm.getAlarmWay());
                            messageRemindDto.setAlarmFrequency(alarm.getAlarmFrequency());
                            messageRemindDto.setAlarmUnit(alarm.getAlarmUnit());
                            messageRemindDto.setAlarmNexus(alarm.getAlarmNexus());
                            messageRemindDto.setUserIds(alarm.getAlarmRoleId());
                            messageRemindDto.setMessageType(3);

                            messageRemindDto.setMessageTypeDict("复检告警");
                            SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                            messageRemindDto.setToday(simpleDateFormat1.format(new Date()));

                            messageRemindDtoList.add(messageRemindDto);
                            //触发提醒，内容为“XX号码、XX名称将在X天后超期复检，请及时处理”

                        }

                    } else {
                        //消息
                        String message = "物料号码:" + wmsStockInfo.getWsiMaterialNumber() + ",物料名称:" + wmsStockInfo.getMaterialName() + "已超期复检，请及时处理";

                        //获取关结方式
                        String alarmNexus = alarm.getAlarmNexus();

                        boolean flag = false;

                        if ("1".equals(alarmNexus)) {
                            for (SysWorkbenchMessage sysWorkbenchMessage : infoList) {
                                if (message.equals(sysWorkbenchMessage.getMessageContent())) {
                                    flag = true;
                                    break;
                                }
                            }
                        }

                        if (flag) {
                            continue;
                        }


                        MessageRemindDto messageRemindDto = new MessageRemindDto();

                        messageRemindDto.setMessage(message);
                        messageRemindDto.setModelType(1);

                        messageRemindDto.setAlarmWay(alarm.getAlarmWay());
                        messageRemindDto.setAlarmFrequency(alarm.getAlarmFrequency());
                        messageRemindDto.setAlarmUnit(alarm.getAlarmUnit());
                        messageRemindDto.setAlarmNexus(alarm.getAlarmNexus());
                        messageRemindDto.setMessageType(3);
                        messageRemindDto.setUserIds(alarm.getAlarmRoleId());
                        messageRemindDto.setMessageTypeDict("复检告警");

                        SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                        messageRemindDto.setToday(simpleDateFormat1.format(new Date()));

                        messageRemindDtoList.add(messageRemindDto);
                        //内容为“XX号码、XX名称已超期复检，请及时处理”

                    }
                }
            }

        }

        if (messageRemindDtoList.size() != 0) {
            MessageRemindMqUtil.messageRemind(messageRemindDtoList);
        }


    }

}
